Constructor overload contains already defines a member with the same signature

后端 未结 3 1917
温柔的废话
温柔的废话 2021-01-28 05:48
public Module(string a, object obj) : this(a, null, obj) { }

public Module(string b, object obj) : this(null, b, obj) { }

These constructor overloads

3条回答
  •  执念已碎
    2021-01-28 06:11

    Parameter names are meaningless in the context of overloads. I can see what you are trying to do, but I'm not sure why. I would dispense with it entirely:

    public Module(string a, string b, object obj){}
    

    Then call the Module constructor, passing in null values as appropriate.

    Module m = new Module(null, "hi", obj);
    
    Module m2 = new Module("bye", null, obj);
    

提交回复
热议问题