I’ve got an abstract class (Object2D), and several class that inherits Object2D (DisplayObject2D for instance)
I use a List to store all references to these objects.
I’d like to iterate through every DisplayObject2D in this List.
So far, the following code is working, but being new to C# development, I wanted to know if there wasn’t any better practice to do so :
List<Object2D> tmp = objects.FindAll( delegate( Object2D obj )
{ return obj is DisplayObject2D; } );
foreach( DisplayObject2D obj in tmp )
{
...
}
Thanks in advance!
if you want an IEnumerable
if you want a List
Note that OfType will give you a more specific type
If it’s not what you expected, use Cast extension to cast it back to an enumerable of base type.