Why ReSharper always suggests to "use var" instead of explicit type usages?

You may read about it ReSharper Code Inspection Wiki; This suggestion is turned on by default.

You can disable this suggestion through "ReSharper | Options | Code Inspection | Inspection Severity":

screen470.png

Have more questions? Submit a request

8 comments

  • Avatar
    Steven Langberg

    this helps.

     

  • Avatar
    Davyd McColl

    As a corollary, I'd really like to enable using the "var" keyword for extracted variables by default. Resharper used to do this before my machine was reloaded -- now I can't seem to find the setting (or help on the net) to re-enable it. To be clear: this isn't to do with the warning insomuch as that, when I press ctrl-r, v, I want to get code like "var someVariableName = <extracted result>"

     

    Help!

  • Avatar
    Alex Berezoutsky

    @Davyd, by default, ReSharper is asking if you'd like to use var or explicit type when introducing variable (see screenshot). You need to have ReSharper IntelliSense enabled for it in the options, though (ReSharper | Options | IntelliSense | General).

  • Avatar
    Davyd McColl

    Thanks, I see that Resharper is remembering my last choice -- I just don't remember it even asking in the past (and, personally, I'd prefer it not to). I could be well wrong about whether or not it was asking -- but I still maintain that I'd prefer it not to ask at all as I'd always like to use var and it's just one extra confirmation I have to go through (:

  • Avatar
    MrXo

    This entry simply does not exist in ReShaper 9. How can I disable this annoying shit?

  • Avatar
    afly
  • Avatar
    Francesc Castells

    I used to have it configured like this (use var only when type is explicit), but in Resharper 9 this setting is gone. How do you get the same behaviour in version 9?

  • Avatar
    Angelina Elycheva

    @Francesc Castells, please try settings in ReSharper | Options | Code Editing | C# | Code Style | 'var' usage in declarations.

Please sign in to leave a comment.