In C#, identifiers such as int
or string
are actually language level keywords.
What is the reason for that?
Note that if the authors wanted to disallow user types with these names, that could have made that a semantic error, not syntax error.
Some clarifications based on answers:
They are keywords because it makes parsing possible/easier
I do not see why, as I am developing a parser, and havingType.Rule = Identifier
is much simpler thanType.Rule = Identifier | "int" | "string" | ...
.They are keywords because they are special aliases
var
anddynamic
are special things as well, but not keywords (for compatibility reasons, nevertheless it demonstrates that being a keyword is not necessary to be special). In a different example, applying[Serializable]
to a type produces magic IL metadata modifierserializable
instead of standard custom attribute. But it is still not a keyword.They are keywords because they were keywords in other languages
Good answer, but then, why are they keywords in other languages? Also, it is certainly possible to highlight them in blue without them being keywords, so why bring that in from other languages?