public partial class Form1 : Form
{
public static void UseParams(params int[] list)
{
string temp = "";
for (int i = 0; i < list.Length; i++)
temp = temp +" " +list[i].ToString();
MessageBox.Show(temp);
}
public static void UseParams2(params object[] list)
{
string temp = "";
for (int i = 0; i < list.Length; i++)
temp = temp + " " + list[i].ToString();
MessageBox.Show(temp);
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UseParams(1, 2, 3);//看参数是3个
UseParams(1, 2); //看参数是2个,可变吧
UseParams2(1, 'a', "test");
int[] myarray = new int[3] { 10, 11, 12 };
UseParams(myarray); //看也可以是容器类,可变吧:)
}
}
{
public static void UseParams(params int[] list)
{
string temp = "";
for (int i = 0; i < list.Length; i++)
temp = temp +" " +list[i].ToString();
MessageBox.Show(temp);
}
public static void UseParams2(params object[] list)
{
string temp = "";
for (int i = 0; i < list.Length; i++)
temp = temp + " " + list[i].ToString();
MessageBox.Show(temp);
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UseParams(1, 2, 3);//看参数是3个
UseParams(1, 2); //看参数是2个,可变吧
UseParams2(1, 'a', "test");
int[] myarray = new int[3] { 10, 11, 12 };
UseParams(myarray); //看也可以是容器类,可变吧:)
}
}