Bonnev
Bonnev

Reputation: 987

Overload type method?

Is there a way to make an overload of a type method?

My goal in this particular situation is to make an overload of string.Substring() with parameters start_index and end_index.

Upvotes: 0

Views: 66

Answers (1)

Konrad Kokosa
Konrad Kokosa

Reputation: 16898

No but you can use so called extension method of a string:

public static class StringExtensions
{
    public static string SubstringRegion(this string str, int startIndex, int endIndex)
    {
        return str.Substring(startIndex, endIndex - startIndex + 1);
    }
}

Upvotes: 2

Related Questions