먼저 문자열 배열을 설정합니다.
string[] num = { "One", "Two", "Three", "Four", "Five"}; Linq LongCount 메서드를 사용하여 요소 수를 가져옵니다.
num.AsQueryable().LongCount();
다음은 전체 코드입니다 -
예
using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
static void Main() {
string[] num = { "One", "Two", "Three", "Four", "Five"};
long res = num.AsQueryable().LongCount();
Console.WriteLine("{0} elements", res);
}
} 출력
5 elements