OrderBy() 排序 根据键按升序对序列的元素排序
OrderByDescending()根据键按降序对序列的元素排序。
Skip()和Take()方法都是IEnumerable<T> 接口的扩展方法,包括C#中的所有Collections类,如ArrayList,Queue,Stack等等,还有数组和字符串都可以调用这两个方法。
int[] test = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
.Skip() 和.Take()
注意在Skip和Take连用时,后者的输入是前者的输出,而不是原输入
Console.WriteLine( string.Concat(test.Skip(2).Take(4)));//注意!结果为{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
.IsNullOrEmpty()
C#字符串之------string的IsNullOrEmpty方法
@注意,IsNullOrEmpty是判断对象即不能为空,也不能为""。如果对象为空或为""都返回true。
string.IsNullOrEmpty(null)---返回true
string.IsNullOrEmpty("")---返回true
string.IsNullOrEmpty("sss")---返回false
---注意,判断时,返回false,才表示对象即不为空也不为""。
.Count();
数组的count属性,是获取该数组的数量值。
count单词本身就有数量、总数的意思。
凡是数组(无论int数组、float数组、string数组等)、列表、集合(collection),都有Count属性(或方法),且该属性返回当前数组或集合的个数,结果相当于Length。
int[] list = new int[] { 5, 2, 8, 6 };
int n = list.Count();//n为4