参数类型params

时间:2021-12-25 09:24:54

params参数练习

 namespace Test
{
class Program
{
static void Main(string[] args)
{
//params 构造函数声明数组,可变数组长度
UseParam1(,,);
UserParam2(,'b',"hello");
Console.ReadKey();
}
public static void UseParam1(params int[] list) //int类型
{
for (int i = ; i < list.Length; i++)
{
Console.Write(list[i]+" ");
}
Console.WriteLine();
}
public static void UserParam2(params object[] list) //object类型
{
for (int i = ; i < list.Length; i++)
{
Console.Write(list[i]+" ");
}
} }
}