Thursday, March 13, 2008

Type inference in .NET 3.0

One of the things I am having a hard time wrapping my head around is why one of the recommendations of Resharper 4.0 is to implicitly type all local variables. It goes against my anal retentive nature for clean, easy to read code.

The following article tries to explain the benefits of this practice, though I’m not sure they have me convinced though I have, at times, found myself annoyed with the redundant declarations of a new variable

i.e.


Dictionary<SearchCriteriaType, SearchCriteriaDisplay> criteriaDisplays = new Dictionary<SearchCriteriaType, SearchCriteriaDisplay>();


Can be shortened to


var criteriaDisplays = new Dictionary<SearchCriteriaType, SearchCriteriaDisplay>();


I guess that makes the code less cluttered. But is life really that much bad with the previous example that the Resharper folks found the need to suggest that it is now best practice?

http://www.programmersheaven.com/2/CSharp3-1

No comments: