먼저 시퀀스를 설정합니다.
List<int> myList = new List<int> { 1, 2, 3, 4 ,5}; 이제 Queryable Sum() 메서드를 사용하여 합계를 찾습니다.
myList.AsQueryable().Sum();
예시
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> myList = new List<int> { 1, 2, 3, 4 ,5};
Console.WriteLine("Sum of elements in a list...");
foreach (int res in myList) {
Console.WriteLine(res);
}
int sum = myList.AsQueryable().Sum();
Console.WriteLine("Sum = {0}", sum);
}
} 출력
Sum of elements in a list... 1 2 3 4 5 Sum = 15