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