0

As it turns out, you can create a class named var and instantiate it with new var();. What influenced the C# developers to allow this to happen with var but not other keywords?

user1306322
  • 8,561
  • 18
  • 61
  • 122

1 Answers1

10

var was only introduced in C# 3.0. It wasn't a keyword at all in older versions of the language. The designers presumably didn't anticipate creating a var keyword at the time they first designed the language, so code was always allowed to use it as an identifier.

That's why var is only a contextual keyword. If it were made a reserved word, existing code would break in the C# 3.0 compiler until all occurrences of var were renamed.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356