我有一个包含以下结果的数组
red
red
red
blue
blue
Green
White
Grey
我想得到数组每个值的重复计数,例如:
red Count=3
blue Count=2
Green Count=1
White Count=1
Grey Count=1
最佳答案
LINQ 使这变得简单:
Dictionary<string, int> counts = array.GroupBy(x => x)
.ToDictionary(g => g.Key,
g => g.Count());
关于c# - 使用计数列出数组重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7832602/