码迷,mamicode.com
首页 > Windows程序 > 详细

C# 可变参数

时间:2015-11-19 14:35:48      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

class Program
    {
        static void Main(string[] args)
        {
            //常规使用方法
            Console.WriteLine(Add(new Int32[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
            //另一种调用方法
            Console.WriteLine(Add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

            Console.ReadKey();
        }

        public static int Add(params Int32[] values)
        {
            int sum = 0;
            foreach (int item in values)
            {
                sum += item;
            }
            return sum;
        }
    }

 

C# 可变参数

标签:

原文地址:http://www.cnblogs.com/imhaiyang/p/4977354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!