static void Main(string[] args) { SayHello("侯志强", 80); SayHello("侯志强"); Console.ReadKey(); } C#4.0实现参数的默认值 static void SayHello(string strName,int nAge=20) { Console.WriteLine("我的名字是{0},今年{1}岁", strName, nAge); } //C#4.0以前实现参数默认值 static void SayHello(string strName1, int nAge) { Console.WriteLine("我的名字是{0},今年{1}岁", strName1, nAge); } static void SayHello(string strName1) { SayHello(strName1, 20); }
来自:http://blog.csdn.net/yisuowushinian/article/details/7566823