CSharp - Will the code compile: static const

Question

Will the code compile?

using System;

class Program
{
    public static const int MYCONST = 100;
    static void Main(string[] args)
    {
        const int MYCONST = 100;
        Console.WriteLine("MYCONST={0}", MYCONST);
    }
}


Click to view the answer

No.

Note

Constants are implicitly static.

We are not allowed to use the keyword static here.

Related Topic