Params参数的应用

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(
123);//看参数是3个
            UseParams(12);   //看参数是2个,可变吧
 
 
            UseParams2(
1'a'"test");
 
            
int[] myarray = new int[3101112 };
            UseParams(myarray); 
//看也可以是容器类,可变吧:)
        }

}
原文地址:https://www.cnblogs.com/xiaobaigang/p/844497.html