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)
{
In C# versions before version 3, implicitly typed local variables were not supported yet, so var
had no special meaning and it was possible to define variables and classes named var
. Your example program is legal, because both occurrences of var
in main
referred to the class var
.
C# 3 and later versions are downwards compatible, so code written in C# before version 3 still compiles with the new compilers.
int
and true
are keywords since C# 1.