Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "var" keyword hampers code readability? [closed]

I just started using Resharper. One of its features is that it suggests changes to the code based on, i suppose, good coding practices.

One of the changes it suggested is to change the variable type to var during assignment. I kept on changing and now the code has var everywhere. Somehow I get the feeling that "var" keyword makes the code a bit difficult to understand.

Is it a good coding practice to use "var" whereever possible or is it better to stick with the actual type. (except anonymous types where its required to use "var")

Thanks.

like image 458
stackoverflowuser Avatar asked Sep 30 '10 21:09

stackoverflowuser


1 Answers

I suggest using var when you have code like this:

var surelyAnXText = new XText(...);

where you always can tell the want type we are declaring a variable of. But not when you have something like this:

var whatIsThis = foo.Some_Method_Where_You_Cant_Tell_The_Return_Type_From_The_Name();
like image 132
Lasse Espeholt Avatar answered Sep 28 '22 08:09

Lasse Espeholt