C# Single() 方法
csharpprogrammingserver side programming更新于 2025/9/14 13:23:00
使用 Single() 方法仅获取序列中的单个元素。
假设我们有一个只有一个元素的字符串数组。
string[] str = { "one" };
现在,获取元素。
str.AsQueryable().Single();
这是我们的代码。
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
string[] str = { "one" };
string res = str.AsQueryable().Single();
Console.WriteLine(res);
}
}
输出
one

