code:
using System;
namespace Constructor
{
class Testing
{
int marks;
static int maxmarks=50;
Testing() //My own default constructor
{
this.marks = 30;
}
Testing(int marks)//parameterized constructors
{
this.marks = marks;
}
Testing(Testing t) //copy constructors
{
this.marks = t.marks;
}
void CalculatePercent()
{
int percent = this.marks * 100 / Testing.maxmarks;
Console.WriteLine(percent);
}
static Test() //static vonstructor
{
Testing.maxmarks = 50;
}
static void Main(string[] args)
{
Testing t1=new Testing();
t1.CalculatePercent();
Testing t2=new Testing(35);
t2.CalculatePercent();
Testing t3=new Testing(t2);
t3.CalculatePercent();
Testing t4=new Testing(45);
Testing t5 = t4;
t4.marks = 60;
t5.CalculatePercent();
Console.ReadKey();
}
}
}
https://www.dotnetperls.com/constructor
https://www.tutorialspoint.com/csharp_online_training/c_constructors.asp