C# | Call Overloaded Methods

Sometimes in C#, to call overloaded methods within the same method names, we still use the old method. In C# there is a neater way to pass arguments to overloaded methods which can be seen below:
Old Way

public MultiLineString(string text)
{
MultiLineString(text, false);
}

public MultiLineString(string text, bool allowEmptyLines)
{
...
}

Neater C# Way

public MultiLineString(string text)
: this(text, false)
{
}

public MultiLineString(string text, bool allowEmptyLines)
{
...
}

Hope this helps!

Hello, nice to meet you

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

1 Comments

Leave a Reply