Counting specific types of objects in ArrayList C #

How do I count the amount of a certain type of object in an ArrayList in C #?

In particular, I have three subclasses of the base class "Letter", "X", "Y" and "Z". Various numbers of X, Y, and Z objects were created and added to the arraylist. Then I need to calculate how many X objects are in this list. What is the best way to do this?

Greetings for helping guys / guys.

+4
source share
1 answer

You can also use OfType <T> Extension Method :

int myCount = myArrayList.OfType<X>().Count() 
+15
source

All Articles