您的位置:首页 > 其它

统计数组中每个元素出现的次数

2016-01-27 16:44 411 查看
Dictionary<string, int> counter = new Dictionary<string, int>();
foreach (string c in  数组)
{
if (counter.ContainsKey(c))
{
counter[c]++;
}
else
{
counter.Add(c, 1);
}
if (counter[max] < counter[c])
max = c;
}

max为元素    counter[max]出现次数最多的元素出现的次数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: