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":

Have more questions? Submit a request

9 Comments

  • 0
    Avatar

    this helps.

     

  • 0
    Avatar

    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!

  • 0
    Avatar

    @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).

  • 0
    Avatar

    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 (:

  • 0
    Avatar

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

  • 0
    Avatar
  • 0
    Avatar

    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?

  • 0
    Avatar

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

  • 0
    Avatar

    I don't know the rational behind this suggestion/rule. Can somebody explain to me why you would want to do this -- set variable to var.

Please sign in to leave a comment.