1. Generate method stub (Ctrl + K + M)
This command is used to generate a stub of the method.
E.g. There is one class Test that does not contain the method “validate()”, and you make an object (objTest) of the class Test, and call method “validate()” - objTest.validate(). Selecting the method “Validate()” pressing Ctrl + K + M will generate a stub of the validate() method like…
private void validate()
{
throw new NotImplementedException();
}
You can do code this method later.
2. Organize usings
There are three options to organize ‘using’ statements at the top of the document. These options are available in Edit menu, Edit -> IntelliSense -> Organize Usings.
a. Remove unused usings: It will remove unused usings from the document.
b. Sort usings: It will sort all usings in the document alphabetically.
c. Remove and Sort: It will remove the unused using statements and sort remaining usings alphabetically.
3. Refactor menu
a. Rename(Ctrl + R + R)
Whenever you rename a variable, method or a property etc. it needs to be updated wherever it is used. Press Ctrl + R + R and Visual Studio will do it for you automatically.
b. Extract method(Ctrl + R + M)
If you want to make a function of some code which is already written somewhere, then by this command Visual Studio will make a method of the selected statements. If the new method needs any arguments or returns a value, Visual Studio will add it automatically too.
c. Encapsulate field(Ctrl + R + E)
If you want make a property of any variable, and want that variable encapsulated then select that variable and press Ctrl + R + E. Visual Studio will make a public property for that variable. Also visual studio will make that variable as a private.
d. Extract interface(Ctrl + R + I)
To make an interface with functions that are already being used in any class, just open that class and click Refactor -> Extract interface. Visual Studio will make an interface with those functions, properties etc. in the class.
e. Promote local variable to parameter(Ctrl + R + P)
Any variable which is declared locally at the method level and you want to pass that variable as parameter of that method. Just select that variable and press (Ctrl + R + P). Visual Studio will remove that variable and will make it as a parameter.
f. Remove parameters (Ctrl + R + V)
If you remove a parameter from an existing method then user needs to remove the parameter from where that method is called. Press Ctrl + R + V, Visual Studio will ask which parameters you want to removed. Select the parameter and click the “Remove” button. Visual Studio will remove the parameter from method itself as well as from where it is being called. Visual studio will show the places where need to be changed.
g. Reorder parameters (Ctrl + R + O)
Similar to “Remove Parameter”, Visual Studio can arrange the parameters in method itself as well as from where it is being called.
4. Snippets
Snippet is nothing but a pre-coded template of code. There are many inbuilt snippets in Visual Studio. You can also create your own snippets!
a. How to use Snippets (Ctrl + K + X)
There is two way to use a snippet.
1. If you want to use a readymade snippet somewhere, press Ctrl + K + X. Select snippet you want to add. Visual Studio will add part of the code for you.
2. Type name of the snippet, press Tab twice and Visual Studio will add part of the code for you.
E.g. 1: type “for” and press Tab twice. Visual Studio will add code of the ‘for’ loop for you.
E.g. 2: type “prop” and press Tab twice. Visual Studio will make a property with get and set for you.
b. How to create Custom Snippet
To create/manage custom snippet, please follow the links below:
i. Create: http://msdn.microsoft.com/en-us/library/ms165394.aspx
ii. Manage: http://msdn.microsoft.com/en-us/library/9ybhaktf.aspx
iii. Code Element http://msdn.microsoft.com/en-us/library/ms171421.aspx
Tip: If you don’t find the “Code Snippet Manager” in the Tools menu, you can add it from Tools -> Customize -> Select Tools in list of “Commands” tab -> drag & drop “Code Snippet Manager” on the Tools menu.
5. Format document (Ctrl + K + D)
This command corrects indentation on the whole document. This command works on both .aspx as well as .cs files.
6. Format selection (Ctrl + K + F)
This command corrects indentation for the selection only. This command works on both .aspx as well as .cs files.
7. Incremental search (Ctrl + I)
This command is used to find text in a document in an incremental manner.
Press Ctrl + I and type whatever you want to search. Visual Studio automatically finds and selects the text you typed. Pressing F3 finds the next match, Shift + F3 finds the match before the cursor’s position.
8. Conditional break point
You can insert a breakpoint which will stop the execution only when a certain condition is satisfied.
E.g.: If there is iteration of users, and you want to break the execution when username = “test” found.
By right clicking the breakpoint user can add condition like username==“test”.
9. Comment selection (Ctrl + K + C)
This command comments the selection.
10. Uncomment selection (Ctrl + K + U)
This command uncomments the selection.
11. Useful shortcuts
1) Full Screen: View –> Full Screen (Shift + Alt + Enter)
2) New line: (Ctrl + Shift + Enter)
3) TO DO List (Task list): Ctrl + \ + T
4) Book Mark (Toggle): Ctrl + K + K
5) Clear all book marks: Ctrl + K + L
6) Go to next book mark: Ctrl + K + N
7) Go to previous book mark: Ctrl + K + P
8) Go to next book mark in same folder: Ctrl + Shift + K + N
9) Go to previous book mark in same folder: Ctrl + Shift + K + P
10) Add task list shortcuts(Toggle): Ctrl + K + H
11) Keep text into toolbar to paste: Drag and drop text onto the toolbar
12) Smart cut/copy/paste: Drag and drop text from one place to another
13) Format document: Ctrl + K + D
14) Incremental Search: Ctrl + K + I
15) Comment: Ctrl + K + C
16) Uncomment: Ctrl + K + U
17) Outlining Expand/Collapse (Toggle): Ctrl + M + M
18) All outlining Expand/Collapse (Toggle): Ctrl + M + L
19) Collapse to definition: Ctrl + M + O
20) Generate method stub: Ctrl + K + M
21) Quick Info: Ctrl + K + I
22) Remove and sort: Ctrl + R + S
23) Insert snippet : Ctrl + K + X
24) Find next: F3
25) Find previous: Shift + F3
26) Go to previous location: Ctrl + -
27) Go to next location: Ctrl + Shift + -
28) Increase indent: Tab
29) Decrease indent: Shift + Tab
30) Code definition window: Definition of selection
Wednesday, May 27, 2009
Subscribe to:
Posts (Atom)