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 Response to “C# | Call Overloaded Methods”

  1. hfrmobile Says:

    The same syntax for ctor overloading 😉


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

%d bloggers like this: