Is there a shortcut in VisualStudio to create a method?

Is there a shortcut in VisualStudio to create a method, like there is "prop, tab" for a property and "ctor, tab" for a constructor?


Solution 1:

There is no Code snippet to create a method other than Main, but you can do the following.

Type your to be method name, pass the parameters, Once done you will notice a blue under line at the beginning of method name. Click that (or click Ctrl + . ) that will give you the option to create method like:

enter image description here

This will generate a method like:

private static void MySomeMethod(int a, string b)
{
    throw new NotImplementedException();
}

Solution 2:

There is another clever way for create method (extract).

This way I use if I have method and I would like part of this method move to new private method.

  1. Select part of code in method which you would like to extract.
  2. Press Ctrl + R + M or right click on selected code → Refactor\Extract\Extract Method...

This will create only new private method but automatically set input parameters and output parameter.