In C # Skip () and Take ()

Skip () and the Take () methods are IEnumerable <T> extensions interface methods, including all classes in C # Collections, such as ArrayList, Queue, Stack and the like, as well as strings and arrays can call these two methods.

int [] = {0 Test,. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9};
test.Skip (I) taken from the subscript indicates the start i, return type IEnumerable <T>, returns included in the set of Test [I]
Console.WriteLine (String.concat (test.Skip (0))) // result is {0,1,2,3,4,5,6,7,8,9 ;; ,}
test.Take (i) represents the subscript i to the end of the interception, the return type IEnumerable <T>, is not included in the returned collection Test [i]
Console.WriteLine (String.concat (test.Take (0))) ; // result is an empty string

 

    1. Note that when used in conjunction Skip and Take, whose input is the output of the former, rather than the original input
      Console.WriteLine 2. ( String.concat (test.Skip ( 2) .Take ( . 4))); // NOTE! The result is {2,3,4,5}
       
      var  testList =  new  List< int >();
      //比如  testList里面是 1,2,3,4,5,6,7,8,9,10
      var  result = testList.Skip(5);   //返回值就是 6,7,8,9,10;
      var  result = testList.Take(5);   //返回值就是 1,2,3,4,5
      //搭配使用,一般用来分页
      var  result = list.Skip(2).Take(2);  //返回值 3,4

Guess you like

Origin www.cnblogs.com/DSC1991/p/11593412.html
Recommended