Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using implicit typing [duplicate]

Possible Duplicate:
Resharper: vars

Is there a reason that resharper suggests var thing1 = 5 as opposed to int thing1 = 5? It just seems that they mean the exact same thing except that var is harder/less comprehensible to a human reader. I would be curious to know if there is a difference in the way that the compiler interprets them, or if its just syntactic sugar.

like image 765
soandos Avatar asked Jun 05 '11 20:06

soandos


2 Answers

No, the generated IL will be exactly the same.

I suspect if you take up Resharper's suggestion, it will also "suggest" going the other way - IIRC the default is to always offer the ability to change in either direction. You can change what it suggests within the options though.

like image 179
Jon Skeet Avatar answered Oct 13 '22 10:10

Jon Skeet


Usage of the 'var' keyword tends to be controversial. The 'authoritative' reference for this debate is http://blogs.msdn.com/b/ericlippert/archive/2011/04/20/uses-and-misuses-of-implicit-typing.aspx

like image 25
Robert Levy Avatar answered Oct 13 '22 09:10

Robert Levy