Type-inferring a constant in C#
- by Andreas Grech
In C#, the following type-inference works:
var s = "abcd";
But why can't the type be inferred when the variable is a constant?
The following throws a compile-time exception:
const var s = "abcd"; // <= Compile time error:
// Implicitly-typed local variables cannot be constant