Posts

Showing posts with the label where

How to use list.where function with the objects getting casted before getting an IEnumerable

How to use list.where function with the objects getting casted before getting an IEnumerable My classes are like this public interface ICar { CarModel GetCarModel(); } public class Honda: ICar { CarModel GetCarModel() { return CarModel.Honda; } } I have a list of ICars defined like this: ICars List<ICar> cars; I am looking to extract a IEnumerable of all cars of type Honda using the Where clause and casted to Honda and not to ICar. How do I do this? Is this possible? BTW more idiomatic C# would use a property not a method: public CarModel CarModel => CarModel.Honda; and it would need to be public to satisfy the interface. – Ian Mercer Jul 1 at 10:53 public CarModel CarModel => CarModel.Honda; public Not, that type design like this leads to "double-typing". Noting p...