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

   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]出现次数最多的元素出现的次数

 

posted @ 2016-01-27 16:44  欲静林鸟  阅读(2209)  评论(0编辑  收藏  举报