1:统计list 内重复值的数量

List<int> list = new List<int>() { 12, 12, 13, 13, 14, 15, 15, 15 };

var g = list.GroupBy(i => i);

foreach (var item in g)
{
Console.WriteLine("Value:{0} , Count:{1}", item.Key, item.Count());
}
结果:
Value:12 , Count:2 Value:13 , Count:2 Value:14 , Count:1 Value:15 , Count:3

2:统计list内某个值的数量

list.FindAll(delegate(int n) { return n == 100; }).Count

List<int> list = new List<int>();
            list.Add(100);
            list.Add(100);
            list.Add(100);
            list.Add(100);
            list.Add(100);
            MessageBox.Show(list.FindAll((ex) => { return ex == 100; }).Count.ToString());

 

posted on 2017-08-23 14:41  小石头的一天  阅读(676)  评论(0)    收藏  举报