C# 中的构造函数链

0 c# constructor constructor-chaining c#-4.0

我正在尝试链接这些构造函数:

public class Method1
{
    public Method1(string a, string b) : this(a, b, "", "")
    {

    }

    public Method1(string c, string d) : this("", "", c, d)
    {

    }

    public Method1(string a, string b, string c, string d)
    {

    }
} 
Run Code Online (Sandbox Code Playgroud)

我有什么办法可以实现这个目标吗?
目前它显示编译时错误。

toa*_*akz 5

您使用的是 C# 4,那么为什么不使用可选参数呢?

 public Method1(string a = "", string b = "", string c = "", string d = "")
Run Code Online (Sandbox Code Playgroud)

您可以将您想要的行为称为:

Method1(c: "some value", d: "some other value");

Method1(a: "some other other value", b:"another other value");
Run Code Online (Sandbox Code Playgroud)

...或参数的任意组合。