var s = "hello"; // s is of type string
var i = 42; // i is of type int
var x = new [] { 43.3 }; // x is of type double[]
var y = new Foo(); // y is of type Foo
使用时您的变量仍然是强类型的var.
作为结果,var不是“邪恶”。相反,它非常方便,正如我所说别处 https://stackoverflow.com/questions/41479/use-of-var-keyword-in-c/41514#41514,我广泛使用它。 Eric Lippert,C# 背后的主要人物之一,也写过非常详细 http://blogs.msdn.com/b/ericlippert/archive/2011/04/20/uses-and-misuses-of-implicit-typing.aspx关于是否var是不好的做法。简而言之,“不”。