I have something like this:
var result = new MyList()
{
Items = new List<Item>(),
...
}
where each Item has, among others, an itemType
property, I need a Dictionary<itemType, count>
which returns the count of each itemType
in my list.
I did this:
var res = new Dictionary<itemType, int>();
res = result.Items.ToDictionary(a => a.itemType,
a=> result.Items.Count(i => i.itemType== a.itemType));}
But I'm getting this error "An item with the same key has already been added" beacuse of course there are several items with the same type in my list, how can I do a group by or a distinct???