Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

IEnumerable.Sumメソッド

Enumerable.Sum メソッド (IEnumerable(Int32)) (System.Linq)
Int32 値のシーケンスの合計を計算します。

SQLでは、SUMに相当します。

ソースコード

using System;
using System.Linq;

namespace LinqSample {
    class Program {
        static void Main(string[] args) {
            int[] numbers = new int[] { 1, 2, 3, 4, 5 };
            Console.WriteLine(numbers.Sum());
            Console.ReadKey();
        }
    }
}

実行結果