统计list中数值出现的个数 返回字典

/// <summary>
/// 统计数组中的重复数据出现的个数
/// </summary>
/// <returns></returns>
private Dictionary<int, int> GetListInfo(List<int> ids)
{
Dictionary<int, int> dic =
new Dictionary<int, int>();

var lst = from v in ids
group v by v into G
orderby G.Key
select new
{
data = G.Key,
count = G.Count()
};
foreach (var v in lst)
{
dic.Add(v.data, v.count);
}
return dic;
}

猜你喜欢

转载自www.cnblogs.com/request/p/12059811.html