C#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 />”);
        }
    }

相关文章