C#Linq First()方法
使用该First()方法从数组中获取第一个元素。
首先,设置一个数组。
int[] arr = {20, 40, 60, 80 , 100};现在,使用QueryableFirst()方法返回第一个元素。
arr.AsQueryable().First();
以下是整个示例。
示例
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
int[] arr = {20, 40, 60, 80 , 100};
//得到第一个元素
int res = arr.AsQueryable().First();
Console.WriteLine(res);
}
}输出结果
20
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短