I am a C ++ programmer learning C #. I am currently reading C # 4.0 in a nutshell.
I came to this statement / snipet on page 74:
Static field initializers are launched in the order in which the fields are declared. The following example illustrates this: X initializes to 0 and Y initializes to 3.
class Foo
{
public static int X = Y;
public static int Y = 3;
}
I do not understand how X can be assigned a value in Y, without the first declaration. Did I miss something?
As well as a side, based on the background in C ++, I usually use the term ctor for the constructor - however, I have not come by comparison with the term in C # - is this the ctor term also used in the C # world?
[change]
The following example on the same page (in the previous book):
class Program
{
static void Main() { Console.WriteLine (Foo.X); }
}
class Foo
{
public static Foo Instance = new Foo();
public static int X = 3;
Foo() { Console.WriteLine (X); }
}
The book states (for the example above):
0, 3 , Foo X 3:
.
, , ctor - , , . , ctor , , "static". , . ?
() ctor X, 3 , - 0. ?!