C# Lists, Foreach, and Types

Posted by user406470 on Stack Overflow See other posts from Stack Overflow or by user406470
Published on 2012-06-26T09:13:27Z Indexed on 2012/06/26 9:15 UTC
Read the original article Hit count: 215

Filed under:

I was wondering if there is a version of foreach that checks only for a specific type and returns it.

For example consider this class tree:

org.clixel.ClxBasic -> org.clixel.ClxObject -> org.clixel.ClxSprite -> WindowsGame1.test

Then consider this code

public List<ClxBasic> objects = new List<ClxBasic>();

foreach(GroupTester tester in objects)
{
    tester.GroupTesterOnlyProperty = true;
}

tester.GroupTesterOnlyProperty is a property created in GroupTester. Is there some way to make something like this work, like an overload of foreach, or another snippet that might help me? I want to make it easy for a programmer to sort through the lists grabbing only what type they need.

© Stack Overflow or respective owner

Related posts about c#