void Start() {
// 作为可变参数进行产地
Debug.Log(Sum(1, 2, 3));
// 作为数组进行传递
Debug.Log(new int[] { 1, 2, 3 });
}
// 可变参数
public int Sum(params int[] a) {
int sum = 0;
foreach (var item in a) {
sum += item;
}
return sum;
}
// 数组传递
public int Sum1(int[] a) {
int sum = 0;
foreach (var item in a) {
sum += item;
}
return sum;
}
标签:int,sum,item,参数,可变,params
From: https://www.cnblogs.com/wuzhongke/p/16883500.html