c# 对list 操作的写法总结
2017-08-23 14:41
218 查看
1:统计list 内重复值的数量
2:统计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());
相关文章推荐
- C#对.CSV格式的文件--逗号分隔值文件 的读写操作及上传ftp服务器操作方法总结
- c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)
- 黄聪:C#使用能够foreach对hashtable、List遍历时“集合已修改;可能无法执行枚举操作。”错误
- C# 对数据库操作的函数总结
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- c#devexpress GridContorl datasource为 类字段的实现方式 非datatable方式以及其他操作总结
- C# - List操作 - 按照字母排序
- C#方便操作数据总结
- C#操作Excel总结
- [C#]DataTable常用操作总结
- 基于C#语言利用Microsoft.office.introp.excel操作Excel总结
- 总结C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 泛型List<T>学习总结
- C#操作Excel(创建、打开、读写、保存)几种方法的总结
- c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)
- Linq常用List操作总结,ForEach、分页、交并集、去重、SelectMany等
- C#操作XML的通用方法总结
- C#执行异步操作的几种方式比较和总结
- C#操作office技术总结
- C#对word、excel、pdf等格式文件的操作总结