How to

overload constructor

Published: 20. October 2011 | Updated: 20. October 2011
License: Microsoft Public License (MS-PL)
Categories: Framework » Basics
Tags: Basics C#
Was this snippet helpful for you? YESYES / NONO

Example

public class MyClass
{
    public MyClass(string text)
    {
        Console.WriteLine("MyClass(string text)");
    }

    // overload
    public MyClass(string text, int number) : this(text)
    {
        Console.WriteLine("MyClass(string text, int number) : this(text)");
    }
}

Use

new MyClass("a", 5);
Console Output:
MyClass(string text)
MyClass(string text, int number) : this(text)
Send us feedback about this snippet »



Related Snippets: