params

将方法中实际参数列表中跟可变参数数组类型一致的类型,都处理为数组中的的元素

 static void Main(string[] arr)
        {
           // int[] numbers={2,3,4,6,7,5,434,341,412} 
            //将后边类型一致的都变成了params中n1数组内容
            Test("小明",1,2,3,4,5,4,3,3,3,4,6,86);
           
            Console.ReadKey();
        }

        public static void Test(string uname,params int[] n1)
        {

            int nums=0;
            for(int i=0 ;i<n1.Length;i++)
            {
                nums += i;
            }
            Console.WriteLine("{0}的总成绩为{1}", uname, nums);
        }

 

相关文章:

  • 2022-12-23
  • 2021-10-22
  • 2021-06-14
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-08-24
猜你喜欢
  • 2021-12-27
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案