using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Params_test
{
    class Program
    {
        int Sum(params int[] i)          //求不定数量的整数之和
        {
            int sum = 0;
            foreach (int k in i)
            {
                sum += k;
            }
            return sum;
        }
        static void Main()
        {
            Program p = new Program();
            int sum;
            sum=p.Sum(1, 2, 3);
            Console.WriteLine(sum);
        }
    }
}


本文转载:CSDN博客