ElementAt()는 특정 인덱스에서 요소를 가져오고 표시하는 데 사용되는 C#의 System.Linq 메서드입니다.
다음은 우리의 문자열 배열입니다 -
string[] arr = { "One", "Two", "Three", "Four", "Five" }; 이제 인덱스 0에 있는 요소를 가져오려면 ElementAt() 메서드를 사용하십시오 -
arr.ElementAt(0);
다음은 완전한 코드입니다 -
예시
using System.IO;
using System;
using System.Linq;
public class Demo {
public static void Main() {
string[] arr = { "One", "Two", "Three", "Four", "Five" };
// displaying element at index 0
string res = arr.ElementAt(0);
Console.WriteLine(res);
}
} 출력
One