1
vote
Casting lists using LINQ #2
Coding Power Unleashed
– In my previous post I showed the LINQ way to cast List<SomeDeriveType> to List<SomeBaseObject>. Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->IEnumerable<BaseObject> baseObjects = DerivedList.Cast<BaseObject>;Great stuff!As @jamiei commented this will raise an exception if the cast fails. OffType<T> will return only the elements of type T despite the fact that you have different derived type in one list. So suppose you have an Animal class and a Cat and Dog class that derive from Animal you could ...
Statistics
|
Visits by Source |
User Actions |




