Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with
class StaticConstructor
{ static StaticConstructor()
{
Console.WriteLine("I am in static Constructor");
}
public StaticConstructor()
{
Console.WriteLine("I am in normal Constructor");
}
}
class Program
{
static void Main(string[] args)
{
StaticConstructor staticConstructor1 = new StaticConstructor();
StaticConstructor staticConstructor2 = new StaticConstructor();
Console.ReadLine();
}
}
No comments:
Post a Comment