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.
You can also use the OfType<T> Extension Method:
int myCount = myArrayList.OfType<X>().Count()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With