Overloaded Constructor in C#.NET

A class can have any number of constructor.

OverloadConstructor is nothing but  the Constructor having different set of parameters.

1.Under this type of situation ,how to call one Constructor to another constructor.

For the below Example when creating Object to the Parameter 2 Constructor it automatically redire
-ct to the Parameter 3 Constructor.The Parameter 2 Constructor wont’t called

///////////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleExample
{
class OverloadedConstructor
{
int i;
string Name;
string Native;

public OverloadedConstructor()
{
Console.WriteLine(“No Parameter Constructor”);
Console.ReadLine();

}
public OverloadedConstructor(string Name, string Native):this(“Pattukkottai”)
{
Console.WriteLine(“2 Parameter Constructor”);
Console.WriteLine(Name);
Console.WriteLine(Native);
Console.ReadLine();
}
public OverloadedConstructor(string Native)
{
Console.WriteLine(“1 Parameter Constructor”);
Console.ReadLine();

}

}
}

Leave a Comment