Sorting:
- By
- ThenBy
- OrderByDescending
- ThenByDescending
- Reverse
1 Public Ienumerable<customer> sortbyname (list<customer> cumtomerlist)2{3 return Customerlist.orderby (c = c.lastname)4 . ThenBy (c = c.firstname); 5 }
A property of that can has null value. Null value is sorted at the first.
Creating:
1 Publicienumerable<int>buildintegersequence ()2 {3 varintegers = Enumerable.range (0,Ten)//0,1,2,3,4,5,6,7,8,94. Select (i =5+(Ten*i));//5, ...5 6 returnintegers;7 }8 9 Publicienumerable<string>buildstringsequence ()Ten { One A varstrings = Enumerable.range (0,Ten) -. Select (I-= (Char)('A'+i)). ToString ());//A,b,c,d,e,f,g,h,i - theRandom Rand =NewRandom (); - varRandomstrings = Enumerable.range (0,Ten) -. Select (I-= (Char)('A'+rand. Next (0, -))). ToString ()); - + returnstrings; -}
Comparing/combining:
- Intersect
- Except
- Concat
- Distinct
- Union
1 Publicienumerable<int>comparesequence ()2 {3 varSEQ1 = Enumerable.range (0,Ten);4 varSEQ2 = Enumerable.range (0,Ten)5. Select (i = i*i);6 7 //return seq1. Intersect (SEQ2); //0,1,4,98 //return seq1. Except (SEQ2); //2,3,5,6,7,89 //return seq1. Concat (SEQ2); //0,1,2,3,4,5,6,7,8,9,0,1,4,9,16,25,36,49,64,81Ten //return seq1. Concat (SEQ2). Distinct (); //Delete Duplicates One returnSeq1. Union (SEQ2);//Also Delete Duplicates A}
C # LINQ