Using LINQ to remove dupicates in dictionary and the count of those duplicates
- by Robert
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());