I have a list that can contain multiple occurrences of the same object. Now I need to calculate how often this object is contained in this list.
int count = 0; foreach (IMyObject item in myList) if (item == object2Count) count++;
I'm sure this can be done better with LINQ, but LINQ is still a mystery to me.
My first question is: how do I count objects through LINQ and the second question is: will this version of LINQ be slower or faster? I use ObservableCollection, and the number of items in the list is usually quite small ... usually no more than 20.
Thanks in advance,
Franc
source share