You can only use type inference for local variables.
The var keyword infers types for variables "that are declared at method scope". In terms of the language, var
is used to define an "implicitly typed local variable declaration" (C# Language Spec 8.5.1). The language only uses var
for local variables, not type-level variables.
As to why, it's a matter of how the C# designers intended it. It was not intended to infer types for all usages, only for a specific scenario. Eric Lippert described why this was done, providing many potential pitfalls that expanding the usage would cause, including potentially publically exposing an anonymous type, chaining multiple initializers, and more.