C# Linq First() 方法
使用 First() 方法获取数组中的第一个元素。
首先,设置一个数组。
int[] arr = {20, 40, 60, 80 , 100};现在,使用可查询的 First() 方法返回第一个元素。
arr.AsQueryable().First();
以下是完整示例。
示例
using System;
using System.Linq;
using System.Collections.Generic;
class Program {
static void Main() {
int[] arr = {20, 40, 60, 80 , 100};
// getting the first element
int res = arr.AsQueryable().First();
Console.WriteLine(res);
}
}输出
20
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP