首页 > 其他 > 详细

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

时间:2019-12-18 15:37:46      阅读:213      评论:0      收藏:0      [点我收藏+]

/// <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;
}

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

原文:https://www.cnblogs.com/request/p/12059811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!