Can we have multiple default constructor for a class in C#
Today I saw the question "Can we have multiple default constructor for a class in C#" in dotnetspider.com forum today. One of the new member who is learning .NET asked this question. So I thought I will clarify the meaning of default constructor here.
In C#, default constructor is nothing but a constructor which takes no parameter. So you cannot create a multiple constructor without any parameter which means you cannot have multiple default constructor, but you can have multiple constructor for a class.
Please refer below sample code,
public class Student{
public Student()
{
//constructor Code goes here
}
public Student(string Subject)
{
//Code goes here
}
public Student(string Subject, int Marks)
{
//Code goes here
}
}