You do not understand: var is not type. var instructs the compiler to use the correct type for the variable based on its initialization.
Example:
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
Your variables are still strongly typed when using var .
As a result, var not "evil." On the contrary, it’s very convenient and, as Ive said elsewhere , I use it extensively. Eric Lippert, one of the main people behind C #, has also described in detail whether var bad practice. In a nutshell, no.
source share