[Mono-devel-list] Bug with static field initializers

Asier Llano Palacios asierllano at infonegocio.com
Thu Sep 11 11:46:49 EDT 2003


I've traed it with .NET Framework 1.1 and it
does also return 0. 
Using an step by step debug, it initializes y after x.
I don't know if it is the correct behaviour
(in ECMA specs), but it is what .NET Framework
1.1 does.

Asier


> -----Mensaje original-----
> De: mono-devel-list-admin at lists.ximian.com [mailto:mono-devel-list-
> admin at lists.ximian.com] En nombre de Chris Seaton
> Enviado el: jueves, 11 de septiembre de 2003 17:23
> Para: mono-devel-list at lists.ximian.com
> Asunto: [Mono-devel-list] Bug with static field initializers
> 
> Look at the code below. From an abstract overview you would expect it to
> print 14, but the output is 0 (it's clear why, x is initialized before
> y, so when Foo is constructed for x, y is still 0). Is this actually a
> bug, or an excepted restriction?
> 
> class Foo
> {
> 	public int z;
> 
> 	public Foo()
> 	{
> 		z = Bar.y;
> 	}
> }
> 
> class Bar
> {
> 	public static Foo x = new Foo();
> 	public static int y = 14;
> 
> 	public static void Main()
> 	{
> 		System.Console.WriteLine(x.z);
> 	}
> }
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list