C#实现函数默认值和C#4.0实现默认值

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

posted @ 2015-11-30 10:27  xp1056  阅读(223)  评论(0编辑  收藏  举报