Search code examples
c#syntaxconstructornullclass-constructors

function() : this(null) {}


Can someone please explain the following syntactic sugar?

protected MyConstructor() : this(null)

Mainly I am interested in this part: ": this(null)"

I know how protected, constructors and "this" keyword work, but am confused and cannot find any detailed information of the last part all put-together in all my online searches.

Edit: I should add that it is in a public abstract class. So I guess the constructor is calling the implementers constructor.

Thanks


Solution

  • It calls another class constructor that has a parameter:

    protected MyConstructor() : this(null) { }  // This calls the other constructor
    
    protected MyConstructor(object whatever)
    {
        Frob(whatever);
    }