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 教师闺蜜祝福语简短