Why does Resharper want you to change most variables to var type instead of the actual type in the code?
It's just an option. You can disable it:
ReSharper -> Options -> Code Inspection -> Inspection Severity -> Code Redundencies -> Use 'var' keyword where possible: change this to "Do not show"
There's also the context (lightbulb) option which will take you in each direction - this is under ReSharper -> Options -> Languages -> C# -> Context Actions -> "Replaces explicit type declaration with 'var'"
I saw a video from Hadi Hariri, where he was presenting Resharper 6.x. His reasoning was, if you are forcing a user to use "var", you are actually forcing him to name the variable in a more meaningful way, that way all the names are readable and make more sense.
By default, it will "green squiggle" declarations of this type :
Person p = new Person();
^^^^^^
Because of the repetition.
It will also suggest (small green underscore) var when it can be inferred :
Person p = repository.GetPerson(1);
¯¯¯
In this case it can be infered because of the return type of the GetPerson method.
As stated by Jon Skeet, you can disable these suggestions in resharper's options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With