6

Is there a shortcut for extracting local variable in VS or ReSharper? I know that there are shortcut for extracting field variable but I cannot find for extracting local variable. Thanks in advance.

DPM
  • 1,540
  • 2
  • 18
  • 40

1 Answers1

4

Right-clicking a local variable, I get this context menu:

ReSharper Context Menu

Assuming you want shortcuts for the highlighted commands, you can define your own shortcuts through the Visual Studio keyboard mapper. (Tools -> Options -> Environment -> Keyboard)

  • Introduce Variable... = "ReSharper.ReSharper_IntroVariable"
  • Introduce Field... = "ReSharper.ReSharper_IntroduceField"
  • Introduce Parameter... = "ReSharper.ReSharper_IntroParameter"

FYI My keyboard shortcuts were set by ReSharper via ReSharper -> Options -> Keyboard & Menus and applying the "Visual Studio" scheme.

(Using Visual Studio Community 2015 and ReSharper Ultimate 2015.2)

Aerom Xundes
  • 244
  • 2
  • 8
  • Thanks for your help. Is there a way when extracting variable to be exact type? For example to be `double x`, not always `var x` ? Or this is a better practice(to use `var` instead of concrete types) in C#? Thanks in advance – DPM Dec 01 '15 at 17:22
  • @DPM I don't think so. ReSharper pushes the `var` keyword pretty hard. As for the usage, I'll refer you to this: [Use of var keyword in C#](http://stackoverflow.com/q/41479/1433521). – Aerom Xundes Dec 09 '15 at 02:53