随笔分类 - Linq
摘要:结论: 值类型 : Contais > Exists > Any (Count) 引用类型 : Exists > Contains > Any (Count) 将对象需要比较的属性增加为3个: 结果: 结论跟上述一样.
阅读全文
摘要:HashSet<T>是一个相对“冷门”的类型,平时在项目中用得不多,但是在特定的业务中可以大用。 先来了解下HashSet<T>类,主要被设计用来存储集合,做高性能集运算,例如两个集合求交集、并集、差集等。从名称可以看出,它是基于Hash的,可以简单理解为没有Value的Dictionary。 Ha
阅读全文
摘要:static void Main(string[] args) { string[] words = { "zero", "one", "two", "three", "four" }; int[] numbers = { 0, 1, 2, 3, 4 }; string[] names ...
阅读全文
摘要:1 //Linq 2 3 //var result = from p in personList 4 // group p by p.Id 5 // into grouped 6 ...
阅读全文
摘要:IEnumerable list = new List { new Person {Age = 12, Id = 2}, new Person {Age = 22, Id = 3}, new Person {Age = 15, Id = 1}...
阅读全文
摘要:GroupJoin 相当于数据库的 Left Join Join 相当于数据库的 Inner Join
阅读全文
摘要:集合 r 是 IEnumerable<T> 类型,该类型的对象具有延迟加载的特性,也就是说, IEnumerable<Student> r = ssList.Where(w => w.StudentID > 2); 这句代码执行后, r 中并没有值,只有当 r 使用时,也就是上述代码中的 ToLis
阅读全文
摘要:IList s1 = new List() { "One", "Two", "Three", "Two", "Three", "wjire" }; IList s2 = new List() { "www", "Tssswo", "Three" }; //从 s1 中删除 s1,s2 都有的元素,...
阅读全文
摘要:var c1 = Enumerable.Empty();//c1.Count=0 var rlist = Enumerable.Range(9527, 10);//{9527,9528,9529,......9536} var rrlist = Enumerable.Repeat(9527, 10);//{9527,9527...
阅读全文
摘要:原来还有这种写法,自己还记了笔记的.悲哀! 一直以来,我都是这样写的: 哎,悲哀! Union 和 Concat 不一样的地方是它要去重
阅读全文
摘要:检查元素的数量,每个元素的值及两个集合中元素的顺序是否相等,3个方面都相等则为true,否则为false
阅读全文
摘要:IList intList = new List() { 10, 21, 30, 45, 50, 87 }; var sum1 = intList.Sum(s => { if (s % 2 == 0) { return s; ...
阅读全文
摘要:IList<Student> studentList = new List<Student>() { new Student() { StudentID = 1, StudentName = "John", StandardID =1 }, new Student() { StudentID = 2
阅读全文

浙公网安备 33010602011771号