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!
Advertisements

One thought on “C# | Call Overloaded Methods

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s