1
vote
Vote UpVote

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 ...
Favorite? Off-Topic? Roland Beenhakker @ 2009-11-06 01:13

Statistics

Visits: 328
Votes: 1
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

jamiei
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

 
Please login or register to use this functionality.
(click on this box to dismiss)