在C#中,以下类型推断有效:
var s = "abcd";
Run Code Online (Sandbox Code Playgroud)
但是,当变量是常数时,为什么不能推断出类型呢?
以下引发了编译时异常:
const var s = "abcd"; // <= Compile time error:
// Implicitly-typed local variables cannot be constant
Run Code Online (Sandbox Code Playgroud)