Override Default Constructor of Partial Class with Another Partial Class

前端 未结 12 1881
时光取名叫无心
时光取名叫无心 2020-12-28 12:59

I don\'t think this is possible, but if is then I need it :)

I have a auto-generated proxy file from the wsdl.exe command line tool by Visual Studio 2008.

Th

12条回答
  •  忘掉有多难
    2020-12-28 13:40

    Sometimes you don't have access or it's not allowed to change the default constructor, for this reason you cannot have the default constructor to call any methods.

    In this case you can create another constructor with a dummy parameter, and make this new constructor to call the default constructor using ": this()"

    public SomeClass(int x) : this()
    {
        //Your extra initialization here
    }
    

    And when you create a new instance of this class you just pass dummy parameter like this:

    SomeClass objSomeClass = new SomeClass(0);
    

提交回复
热议问题