Sums the specified list. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IList

Description

Sums the specified list.

Demo Code


using System.Collections.Generic;
using System.Collections;
using System;// w  ww  . j  a va2  s . c om

public class Main{
        /// <summary>
        /// Sums the specified list.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static int Sum(IList<int> list)
        {
            int sum = 0;
            foreach (int n in list)
            {
                sum += n;
            }
            return sum;
        }
}

Related Tutorials