Chỉ lấy một phần tử duy nhất của dãy bằng phương thức Single ().
Giả sử chúng ta có một mảng chuỗi chỉ có một phần tử.
string[] str = { "one" }; Bây giờ, hãy lấy phần tử.
str.AsQueryable().Single();
Đây là mã của chúng tôi.
Ví dụ
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);
}
} Đầu ra
one