{
//Private fields of class
int A, B;
//default Constructor
public Test1()
{
A = 10;
B = 20;
}
//Paremetrized Constructor
public Test1(int X, int Y)
{
A = X;
B = Y;
}
//Method to print
public void Print()
{
Console.WriteLine("A = {0}\tB = {1}", A, B);
}
static void Main()
{
Test1 T1 = new Test1(); //Default Constructor is called
Test1 T2 = new Test1(80, 40); //Parameterized Constructor is called
T1.Print();
T2.Print();
Console.Read();
}}
one more example:
class Test3
{
public Test3()
{
Console.WriteLine("Instance Const");
}
static Test3()
{
Console.WriteLine("Static Const");
}
static void Main()
{
//Static Constructor and instance constructor, both are invoked for first instance.
Test3 T1 = new Test3();
//Only instance constructor is invoked.
Test3 T2 = new Test3();
Test3 t3 = new Test3();
Console.Read();
}
}

Prasenjit DeyRank #6,279 · 271 reputationPosted Sep 16, 2013, 4:20 AM EDT
{
//Private fields of class
int A, B;
//default Constructor
public Test1(int x = 10, int y = 20)
{
A = x;
B = y;
}
You also can do this. If you use optional parameter, you don't have to overload the constructor (for default constructor in your example), your work will be done just declare one constructor only
Jeetendra GundRank #97 · 22.1K reputationPosted Sep 16, 2013, 4:26 AM EDT
public class mySampleClass {
public mySampleClass()
{
// This is the no parameter constructor method.
// First Constructor
}
public mySampleClass(int Age)
{
// This is the constructor with one parameter.
// Second Constructor
}
public mySampleClass(int Age, string Name)
{
// This is the constructor with two parameters.
// Third Constructor }
// rest of the class members goes here. }
This way also
Pavan RamamurthyRank #1,682 · 906 reputationPosted Sep 16, 2013, 4:41 AM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 16, 2013, 5:17 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 16, 2013, 8:30 PM EDT
your code is correct.
are you facing any problem to create constructor?