Today I noticed we can define a class named var
or dynamic
. First, I thought it\'s not possible because these are special keywords and cannot be used a
These are called contextual keywords.
They only behave as keywords if you don't have your own types with those names.
The point of this is to allow exactly what you just did.
Because these keywords were introduced by newer versions of C# (3.0 and 4.0), it's possible (though unlikely) that some existing codebases have classes with those names, just like you made.
Therefore, if the compiler sees such classes, it will compile exactly the way it used to and treat them as regular classes rather than keywords.