params 关键字载入空值的陷阱
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.ShowInfo("cjijhsakj", 100, null);//参数赋null值,就会得不到效果
}
public void ShowInfo(params object[] parameters)
{
string strOutPut = string.Empty;
for (int i = 0; i < parameters.Length; i++)
{
if (parameters[i] == null)//修复载入载入空值的问题
{
strOutPut += "null" + "\r\n";
}
else
{
strOutPut += parameters[i].ToString() + "\r\n";
}
}
Console.Write("参数列表:\n{0}", strOutPut);
Console.Read();
}
}