CSharp - What is the output: enum initialization readonly?


What is the output of the following code?

using System;
class Program
    readonly int MYCONST = 50;//ok
    enum Values { val1, val2 = MYCONST, val3, val4 = 21, val5 };
    static void Main(string[] args)
        int x1 = (int)Values.val1;
        int x2 = (int)Values.val2;
        int x3 = (int)Values.val3;
        int x4 = (int)Values.val4;
        int x5 = (int)Values.val5;
        Console.WriteLine("x1={0}", x1);
        Console.WriteLine("x2={0}", x2);
        Console.WriteLine("x3={0}", x3);
        Console.WriteLine("x4={0}", x4);
        Console.WriteLine("x5={0}", x5);


Click to view the answer

No. We will encounter a compilation error.

Related Quiz