首页 > 其他 > 详细

List<string>里 每个元素重复了多少次

时间:2015-09-23 10:26:59      阅读:176      评论:0      收藏:0      [点我收藏+]
List<string>里 每个元素重复了多少次


static void Main(string[] args) { List<string> list = new List<string>(); list.Add("aaa"); list.Add("aa"); list.Add("dd"); list.Add("aaa"); list.Add("dd"); list.Add("aa"); list.Add("aaa"); int a = RepeatTimes(list, "aaa");//某个对象重复有多少次 //打印出重复多少次 foreach (var item in list.GroupBy(s => s)) { Console.WriteLine("{0}:{1}次", item.Key, item.Count()); } } /// <summary> /// 某个元素重复次数 /// </summary> /// <param name="L"></param> /// <param name="text"></param> /// <returns></returns> private static int RepeatTimes(List<string> list, string text) { int num = 0; foreach (string str in list) if (str == text) num++; return num; }

 

List<string>里 每个元素重复了多少次

原文:http://www.cnblogs.com/Luouy/p/4831238.html

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