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)
{
Keywords can be reserved contextually. When the source code is parsed, that context is established as part of the parse tree. The evaluation of keywords takes place within that context. So, in this case, var isn't in a reserved context and won't have the same meaning as when you're using it in an assignment statement. I believe one reason for this flexibility is that var was introduced in C# 3, so making it reserved everywhere might have broken backwards compatibility in some programs, whereas using it as a variable type declaration wouldn't have compiled in earlier versions, so there's no breakage.