Linq Sum() 메서드를 사용하여 요소의 합을 찾습니다.
다음은 정수 요소가 포함된 목록입니다.
List<int> list = new List<int> { 99, 34, 77, 75, 87, 35, 88}; 이제 Sum() 메서드를 사용하여 합계를 찾습니다.
list.AsQueryable().Sum();
다음은 정수 요소가 있는 목록의 요소 합을 찾는 예입니다.
예시
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> list = new List<int> { 99, 34, 77, 75, 87, 35, 88};
int res = list.AsQueryable().Sum();
Console.WriteLine("Sum = {0}", res);
}
} 출력
Sum = 495