例:
public class Test
{
public Max(int... num)
{
int max = 0;
int length = num.length;
for(int i=0;i<length;i++)
{
if(max<num[i])
max = num[i];
}
return max;
}
int Use()
{
int max = Max(1,7,3,6,0);
return max;
}
}
解析:
<Type>... name:参数定义
name[i]:调用第i个参数
那么在使用函数后会自动将参数放入一个动态数组中,并通过数组的方式进行管理