Linq Last() 메서드를 사용하여 시퀀스에서 마지막 요소를 가져옵니다.
다음은 우리의 배열입니다.
int[] val = { 10, 20, 30, 40 }; 이제 마지막 요소를 가져옵니다.
val.AsQueryable().Last();
예시
using System;
using System.Collections.Generic;
using System.Linq;
class Demo {
static void Main() {
int[] val = { 10, 20, 30, 40 };
// getting last element
int last_num = val.AsQueryable().Last();
Console.WriteLine("Last element: "+last_num);
}
} 출력
Last element: 40