ForEach :对 System.Collections.Generic.List<T> 的每个元素执行指定操作
来源:互联网 发布:千牛mac版不响 编辑:程序博客网 时间:2024/05/16 10:08
效果:
Dep,Arr,Cabin字段进行组合
using System;using System.Collections.Generic;using System.Diagnostics;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Test.Con{ class Program { static void Main(string[] args) { List<Policy> list = new List<Policy>(); for (int i = 0; i < 30000; i++) { list.Add(new Policy { AirCode = "CA", Dep = "PEK,CAN,CTU", Arr = "PEK,CAN,CTU,SHA", Cabin = "D,M,Y" }); } Stopwatch sp = new Stopwatch(); sp.Start(); List<Policy> result = new List<Policy>(); list.ForEach(m => { var s = (from d in m.Dep.Split(',') from a in m.Arr.Split(',') from c in m.Cabin.Split(',') where d != a select new Policy { AirCode = m.AirCode, Dep = d, Arr = a, Cabin = c }).ToList(); s.ForEach(n => { result.Add(n); }); }); sp.Stop(); //result.ForEach(m => //{ // Console.WriteLine(m.ToString()); //}); Console.WriteLine("count:{0},time:{1}", result.Distinct().Count(),sp.ElapsedMilliseconds); Console.Read(); } } public class Policy { public string AirCode { get; set; } public string Dep { get; set; } public string Arr { get; set; } public string Cabin { get; set; } public override string ToString() { return string.Format("AirCode:{0},Dep:{1},Arr:{2},Cabin:{3}", AirCode, Dep, Arr, Cabin); } }}
0 0
- ForEach :对 System.Collections.Generic.List<T> 的每个元素执行指定操作
- System.Collections.Generic.IEnumerable<T>接口
- 使用指定的比较器对整个 System.Collections.ArrayList 中的元素进行排序。
- [corefx注释说]-System.Collections.Generic.Stack<T>
- [corefx注释说]-System.Collections.Generic.Queue<T>
- VS2005的System.Collections.Generic.List的一些查找方法的不足
- System.Collections.Generic
- C++与C#对常用数据结构封装的对比(STL vs System.Collections.Generic)
- C++与C#对常用数据结构封装的对比(STL vs System.Collections.Generic)
- python对list中的每个元素进行某种操作
- error C3225: generic type argument for 'T' cannot be 'System::Collections::Generic::KeyValuePair ^',
- 根据给出的值、判断是否构成三角形及类型using System; using System.Collections.Generic; using System.Linq; using System.T
- System.Collections、System.Collections.Generic、System.Collections.Specialized
- System.Collections.Generic 命名空间
- System.Collections.Generic命名空间
- System.Collections.Generic 命名空间
- System.Collections.Generic 命名空间
- ASP.Net 之 System.Collections.Generic 下的容器类
- javascript中的原型属性和实例属性
- 数据库rac启停步骤.txt
- NPAPI脚本化接口
- C#如何生成静态页面
- ListView的插入和编辑模板实例
- ForEach :对 System.Collections.Generic.List<T> 的每个元素执行指定操作
- NPAPI 插件运行流程分析
- MATLAB关闭科学计数法显示
- javascript函数querySelector
- cocos2d-x 安卓环境配置 -转
- Junit 跟XML解析实例
- Python学习笔记——print语句用法总结
- ThinkPHP 的模型使用详细介绍--模型的核心(七)
- 位运算—-异或