Reputation: 1036
how does one go about counting the amount of a specific object type in an ArrayList in C#?
More specifically, I have three subclasses of base class 'Letter', 'X', 'Y' and 'Z'. Various amounts of X, Y and Z objects have been created and added to an arraylist. I then need to count how many X objects are in that list. What's the best way of going about this?
Cheers for any help guys/gals.
Upvotes: 4
Views: 2015
Reputation: 139758
You can also use the OfType<T> Extension Method:
int myCount = myArrayList.OfType<X>().Count()
Upvotes: 15