Using LINQ to remove dupicates in dictionary and the count of those duplicates

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-05-31T01:37:41Z Indexed on 2010/05/31 1:42 UTC
Read the original article Hit count: 317

Filed under:
|

I have some code that returns unique elements in my dictionary, but I would also like to return the count of the duplicate elements. Basically change dictionary[key, uniqueelement] to dictionary[uniqueelement, count]. Here is my code that just returns the unique elements.

var uniqueItems = deviceInstances.Children.GroupBy(pair => pair.Value.Information.UnderlyingDeviceType)
                  .Select(group => group.First())
                  .ToDictionary(pair => pair.Key, pair => pair.Value.Information.UnderlyingDeviceType.ToString());

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ