First of all, I got an answer in What is the use of static constructors?, but I want an answer in this context.
Here is my C# static class:
public static class BasicClass
{
static int i = 0;
static BasicClass()
{
i = 10;
}
public static void Temp()
{
//some code
}
public static void Temp1()
{
//some code
}
}
Inside this I have a static variable i
which is initialized to 10 when it is first called. So basically it may be the purpose of a static constructor but the same thing can be achieved without declaring a static constructor by initializing the static int i = 10
which serves the same purpose that is gets initialized only once.
Then why do we need a static constructor? Or am I completely wrong in understanding the concept or use of static constructors?