class A
{
A()
{
var x = 5; // this is allowed
}
var _x = 5; // the compiler is unhappy
}
Run Code Online (Sandbox Code Playgroud)
我想编译器必须能够推导出成员变量的类型,就像它对本地变量一样.那有什么区别?
有没有人知道或关心为什么隐式类型仅限于局部变量?
var thingy = new Foo();
Run Code Online (Sandbox Code Playgroud)
但为什么不......
var getFoo() {
return new Foo();
}
Run Code Online (Sandbox Code Playgroud)