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 />");
        }
    }

原文地址:https://www.cnblogs.com/51net/p/2390473.html