Why can I create a class named “var”?

后端 未结 5 1879
-上瘾入骨i
-上瘾入骨i 2020-12-05 09:22

Isn\'t var a keyword in C#? But why can I do this:

public class var { }

public class main
{
    public static void main(string[] args)
    {
           


        
5条回答
  •  无人及你
    2020-12-05 09:48

    The compiler is smart enough to know that the context you are using var as a class name is never a context for the keyword so allows it (which is why it is defined as a contextual keyword).

提交回复
热议问题