For advanced query methods, mainly divided into five categories, details:
"Distinct": Avoid duplicate values, that is, if there are two number 2, then use the collection class can appear single
First, let's write an array that's handy for example:
Array data persons int[] Arr = {25, 36, 25, 2, 3, 9, 55, 581, 21, 15, 44, 78, 96};
Console.WriteLine ("Arr Max:" + Arr.max ()); Console.WriteLine ("The Minimum value of ARR:" + arr.min ()); Console.WriteLine ("The average of Arr:" + arr.average ()); Console.WriteLine ("Number of array elements in ARR:" + arr.count ()); Console.WriteLine ("The Sum of ARR:" + arr.sum ());
simple to understand is to use the array of ARR properties to display the desired effect:
- Sort class, Keyword ThenBy
var result = Arr.orderby (p = = p.tostring (). Substring (0, 1)); According to the first number from small to large sort var result = Arr.orderby (p = = p.tostring (). Substring (0, 1)). ThenBy (p = p); Two orders //descending permutation var t = Arr.orderby (P = = p.tostring (). Substring (0, 1)); var result = from P in T is the P descending select p;
three methods, the first display effect is sorted by the first number, but this method generally does not meet the requirements, and second, on the basis of the first order from small to large, and the third is in descending order.
The second kind of display effect:
Take a skip,skip and skip the idea
var result = Arr.skip (2). Take (3); Skip two and fetch three values var result = Arr.skip (3); Skips the value of three, after the remainder of the var result = arr.skipwhile (P = P >1); Remove all values after the remaining greater than or equal to p, such as p>1, where all values are satisfied, so the output value is 0 var result = arr.takewhile (P = p > 4); Remove all values that meet the criteria for the first time, and stop execution when a non-conforming condition is encountered
in the upper array, because each value is greater than 1, the value of the third output is null, and the last one to 2 does not satisfy the condition and stops execution, so the output is:
For the last generated class, it is not the previous extension method, but the normal static method
Range can only produce integer sequences, repeat can only produce generic sequences
Example:
var result = System.Linq.Enumerable.Repeat (DateTime.Now, ten); Show current date, and number of times
The five major categories mainly include LINQQ's various common query methods, others continue to learn in practice.
Linq-Advanced Query method