Why built-in types in C# are language keywords?

Viewed 523

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:

  1. They are keywords because it makes parsing possible/easier
    I do not see why, as I am developing a parser, and having Type.Rule = Identifier is much simpler than Type.Rule = Identifier | "int" | "string" | ....

  2. They are keywords because they are special aliases
    var and dynamic 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 modifier serializable instead of standard custom attribute. But it is still not a keyword.

  3. 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?

3 Answers
Related