C# 4.0命名参数和可选参数

虽然4.0有了新特性。

Named And Optional Arguments - 命名参数和可选参数

public partialclass NamedAndOptionalArguments : System.Web.UI.Page
    {
       
protectedvoid Page_Load(object sender, EventArgs e)
        {
            Write(
"hello");
            Write(
"hello","webabcd");
            Write(
"hello", p3:false, p2:"webabcd");
        }

       
privatevoid Write(string p1,string p2 = "p2",bool p3= true)
        {
            Response.Write(
string.Format("p1:{0}; p2:{1}; p3:{2}", p1, p2, p3.ToString()));
            Response.Write(
"<br />");
        }
    }

posted @ 2011-11-05 17:12  跟着阿笨一起玩.NET  阅读(221)  评论(0编辑  收藏  举报