""When you initialize a static variable, the initialization always takes place before any reference is made to that variable"" I `am not understanding how this sentence is true ,please give an example in support of this sentence.
Static field initialization how takes place
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.


Manas MohapatraRank #182 · 13.2K reputationPosted Dec 10, 2015, 8:19 PM EST
Please go through below example: Here there are three classes Test, First, second. In Test class it displays output which depends on First and Second. First class declares a static variable called X which calls static function of class Test . In same way class Second declares a static variable called Y which calls static function of class Test using System; class Test { static void Main() { Console.WriteLine("{0} {1}", Second.Y, First.X); } public static int F(string s) { Console.WriteLine(s); return 1; } } class First { public static int X = Test.F("First A"); } class Second { public static int Y = Test.F("Second A"); } Output: First A Second A