如何使用List类内部方法计算List元素之和

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication1
{
    partial class Program
    {




        static void Main(string[] args)
        {
            Program p = new Program();
            List list = new List();
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.AddRange(new List { 1, 2 });
            int result = list.Aggregate(a);
            Console.Write(result);
            Console.ReadKey();
        }
        //此处是累加方法,通过委托传递给Aggregate方法参数中
        static int Plus(int a, int b)
        {
            return a + b;
        }
        public static event Func a = Plus;
    }
}

你可能感兴趣的:(C#基础知识)