CSharp - What is the output: enum initialization?

Question

What is the output of the following code?

using System;
class Program
{
    int a = 50;
    enum Values { val1, val2 = a, val3 = 12, val4, val5 };
    static void Main(string[] args)
    {
        int x1 = (int)Values.val1;
        int x5 = (int)Values.val5;
        Console.WriteLine(x1);
        Console.WriteLine(x5);
    }
}


Click to view the answer

Compilation error.

Note

So if we change int a =25 to static int a=25, will the preceding code compile?

We cannot use variables in this manner.

Related Quiz