C#学习(函数参数数组,函数参数不确定)

c#函数的参数个数不确定,且类型相同的情况,使用参数数组

//使用params关键字将参数打包成数组
static int plus(params int[] arr){
	int sum = 0;
	foreach(int a in arr){
		sum += a;
	}
	return sum
} 

static void Main(string[] args){
	console.WriteLine(plus(1,2,3,4,5,6,7,8));
}
发布了62 篇原创文章 · 获赞 28 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/native_lee/article/details/88762698