Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shortcut in VisualStudio to create a method?

Tags:

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

like image 686
Jo Smo Avatar asked May 22 '14 15:05

Jo Smo


People also ask

What is Ctrl Shift F in Visual Studio?

Ctrl-Shift-F is used to find all the ocuurance of a string with in entire solution and display find result window as shown below. Ctrl-F is used to find a string in the current document, project and all open documents one by one.

How do you enter a method in Visual Studio?

To navigate to a class or type, choose it in the middle drop-down. To navigate directly to a procedure or other member of a class, choose it in the right drop-down. To shift focus from the code window to the navigation bar, press the shortcut key combination Ctrl+F2.


2 Answers

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();
}
like image 135
Habib Avatar answered Sep 20 '22 05:09

Habib


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.

like image 22
Dušan Kalivoda Avatar answered Sep 23 '22 05:09

Dušan Kalivoda