我有一些代码可以返回字典中的唯一元素,但我也想返回重复元素的计数。基本上将dictionary[key, uniqueelement]更改为dictionary[uniqueelement, count]。以下是仅返回唯一元素的代码。
var uniqueItems = deviceInstances.Children.GroupBy(pair => pair.Value.Information.UnderlyingDeviceType)
.Select(group => group.First())
.ToDictionary(pair => pair.Key, pair => pair.Value.Information.UnderlyingDeviceType.ToString());