隐式输入;为什么只是局部变量? [英] Implicit typing; why just local variables?
本文介绍了隐式输入;为什么只是局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道或想推测为什么隐式类型仅限于局部变量?
Does anyone know or care to speculate why implicit typing is limited to local variables?
var thingy = new Foo();
但为什么不...
var getFoo() {
return new Foo();
}
推荐答案
Eric Lippert 就此主题撰写了整篇博文.
Eric Lippert did an entire blog post on the subject.
总而言之,主要问题是它需要对 C# 编译器进行重大的重新架构才能这样做.声明目前以单程方式处理.由于能够在推断变量之间形成循环,这将需要多次通过.VB.NET 也有大致相同的问题.
In summary, the main problem is that it would have required a major re-architecture of the C# compiler to do so. Declarations are currently processed in a single pass manner. This would require multiple passes because of the ability to form cycles between inferred variables. VB.NET has roughly the same problem.
这篇关于隐式输入;为什么只是局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文