paramsパラメータの呼び出し

2099 ワード

namespace params 
{
    class Program
    {
        public static void Test(string name,params int[] score)
        {
            int sum = 0;
            for (int i = 0; i < score.Length; i++)
            {
                sum += score[i];
            }
            Console.WriteLine("{0} {1}",name,sum);
        }
        static void Main(string[] args)
        {
            //int [] s={98,97,99};
            Test(" ", 97, 98, 99);// params , , 。
            Console.ReadLine();
        }
    }
}

注意:params可変パラメータは、パラメータリストの最後の要素である必要があります.