class Program
{
static void Main(string[] args)
{
int[] a ={ 1, 2, 3 };
F(a);
F();
Console.ReadKey();
}
//params数组参数必须位于方法参数列表最后一个,只能是一维数组
static void F(params int[] args)
{
//输出数组参数的元素个数
Console.WriteLine("Array contains {0} elements:",args.Length);
//输出数组参数所有元素
foreach (int i in args)
Console.Write(" {0} ",i);//write不换行
Console.WriteLine();//换行处理
}
}
{
static void Main(string[] args)
{
int[] a ={ 1, 2, 3 };
F(a);
F();
Console.ReadKey();
}
//params数组参数必须位于方法参数列表最后一个,只能是一维数组
static void F(params int[] args)
{
//输出数组参数的元素个数
Console.WriteLine("Array contains {0} elements:",args.Length);
//输出数组参数所有元素
foreach (int i in args)
Console.Write(" {0} ",i);//write不换行
Console.WriteLine();//换行处理
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-718182/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-718182/