【发布时间】:2014-11-21 16:23:15
【问题描述】:
使用 vs 2010 C#
我有以下数组,我正在尝试查找是否有重复项 在数组中。我也想知道他们的索引
red
red
Grey
Grey
red
blue
blue
Green
White
Grey
我想得到数组每个值的重复计数,例如:
red Count=2 index=0 (contain the duplicate cluster start index)
Grey Count=2 index=2
red Count=1 index=4
blue Count=2 index=5
Green Count=1 index=6
White Count=1 index=7
Grey Count=1 index=8
帮我修正下面的语法以完全填充上述结果
var result = from p in a //a is the list
group p by p into g
select new { value=g.Key,count=g.Count()};
【问题讨论】:
-
该代码会产生什么?您希望看到它如何改变?
-
@shamim - 你有机会看看我的答案吗?