More on inline initialization

Let’s play. What will this program output to the console:

namespace Test

{

    public class Program

    {

        private static void Main()

        {

            System.Console.WriteLine(MyClass.Field);

        }

    }

 

    public class MyClass

    {

        private static readonly int _height = 3;

        private static readonly int _width = 2;

        public static readonly int Field = _width*_height;

    }

}

Do I hear ‘6’? Ok, this was easy. And how about this one?

namespace Test

{

    public class Program

    {

        private static void Main()

        {

            System.Console.WriteLine(MyClass.Field);

        }

    }

 

    public class MyClass

    {

        private static readonly int _height = 3;

        public static readonly int Field = _width * _height;

        private static readonly int _width = 2;

    }

}

Any guess (without actually running the code)?
Technorati Tags: