Hello everybody
Which static class initialize first if we have one more static classes in our project?
For example : Below code gives null exception.
class Program
{
static void Main(string[] args)
{
First.Write();
Second.Write();
}
}
static class First
{
public static int[] firstArray = new int[20];
public static int[] secondArray = Second.secondArray;
public static void Write()
{
Console.WriteLine(firstArray.ToString());
Console.WriteLine(secondArray.ToString());
}
}
static class Second
{
public static int[] firstArray = First.firstArray;
public static int[] secondArray =secondArray = new int[30];
public static void Write()
{
Console.WriteLine(firstArray.ToString());
Console.WriteLine(secondArray.ToString());
}
}
If you give attention, you will see that if First class will initialize itself so secondArray field of Second would be null.But if Second class would initialize first so Second class firstArray would be null.I am trying to tell that which initialize first makes different results.
I think that it is abstract question about my project.I encounter it while trying to understand why i am getting unexpected results.