Professional Documents
Culture Documents
To define a Destructor
~ + tab tab
Code snippet:
~_Default()
2. To create an Attribute
Code snippet:
true)]
// http://go.microsoft.com/fwlink/?LinkId=85236
this.positionalString = positionalString;
}
3. Checked keyword
Code snippet:
checked
4. Creating a Class
Code snippet:
class MyClass
5. Creating a Constructor
public _Default()
{}
6. Console.WriteLine() shortcut
cw + tab tab
Code snippet:
Console.WriteLine ();
7. Do..while loop
do + tab tab
Code snippet:
do
{
} while (true);
8. Else statement
else
{}
9. Enum
enum MyEnum
10. Equals
//
// http://go.microsoft.com/fwlink/?LinkID=85237
// http://go.microsoft.com/fwlink/?LinkId=85238
//
return false;
return base.Equals(obj);
}
// override object.GetHashCode
return base.GetHashCode();
11. Exceptions
[Serializable]
public MyException() { }
inner)
}
protected MyException
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
14. Reverse for loop
Code snippet:
15. If statement
if + tab tab
Code snippet:
if (true)
}
16. Indexer
Code snippet:
17. Interface
interface IInterface
}
18. Invoke- to safely invoke the event
Code snippet:
if (temp != null)
temp();
Code snippet:
Code snippet:
get
this.outer = outer;
}
get
//
//
//
return default(ElementType);
Code snippet:
lock (this)
{}
Code snippet:
global::System.Windows.Forms.MessageBox.Show("hello");
23. Action
mvcaction +tab tab
Code snippet:
return View();
Code snippet:
[HttpPost]
return View();
namespace MyNamespace
Code snippet:
Code snippet:
{
return (int)obj.GetValue(MyPropertyProperty);
obj.SetValue(MyPropertyProperty, value);
DependencyProperty.RegisterAttached("MyProperty", typeof(int),
Code snippet:
{
get { return (int)GetValue(MyPropertyProperty); }
DependencyProperty.Register("MyProperty", typeof(int),
Code snippet:
Code snippet:
return 0;
struct MyStruct
Code snippet:
{}
Code snippet:
switch (switch_on)
{
default:
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
Code snippet:
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod]
37. Try..catch
try + tab tab
Code snippet:
try
{}
catch (Exception)
throw;
38. Try..finally
Code snippet:
try
{}
catch (Exception)
{
throw;
Code snippet:
unchecked
Code snippet:
unsafe
Code snippet:
using (resource)
Code snippet:
public static
global::System.Workflow.ComponentModel.DependencyProperty
InvokeEvent =
global::System.Workflow.ComponentModel.DependencyProperty.Register(
[System.ComponentModel.Description("Invoke")]
[System.ComponentModel.Category("Invoke Category")]
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.DesignerSerializationVisibility(System.Compon
entModel.DesignerSerializationVisibility.Visible)]
add
base.AddHandler(_Default.InvokeEvent, value);
remove
base.RemoveHandler(_Default.InvokeEvent, value);
public static
global::System.Workflow.ComponentModel.DependencyProperty
MyPropertyProperty =
global::System.Workflow.ComponentModel.DependencyProperty.Register(
[System.ComponentModel.Description("MyProperty")]
[System.ComponentModel.Category("MyProperty Category")]
[System.ComponentModel.Browsable(true)]
System.ComponentModel.DesignerSerializationVisibility(System.Compone
ntModel.DesignerSerializationVisibility.Visible)]
get
return ((string)(base.GetValue(_Default.MyPropertyProperty)));
}
set
base.SetValue(_Default.MyPropertyProperty, value);
Code snippet:
while (true)
2. Its sometimes really helpful and more appealing for developers to work
in full screen mode
Editing
1. For Copying a line in the IDE just go to the start of the line and press Ctrl+C,there is
no need to select anything
2. For Pasting a line just go to the start of the line and just press Ctrl+V
3. For Deleting a line just go to the start of the line and press Ctrl+X, this is not
actually delete but its similar to cut if you do Ctrl+X on current line and go to some
other place in your code and do Ctrl+V then it will paste the same line there.
5. If you want to collapse all your code units or blocks to their definitions
then the shortcut to achieve this is Ctrk+M+O or Ctrl+M Ctrl+O.This is also a
very handy shortcut which helps a lot in development.
1. This shortcut helps me to write beautiful and decorative code which is easy to
understand by any person.
2. Shortcut is just press Ctrl+K+D.
3. This works not only in C# and VB code behind but it works well in aspx pages.
4. If you want to just format the selected piece of code then just press Ctrl+K+F .
1. Generating dummy getter and setters or properties is also a pain in big projects.
2. Although i would recommend you some refactors like Resharper which can do it
for you or some code generators like Code Smith and also give a try to inbuilt on
in Visual Studio 2008 called T4 or Text Template Transformation Toolkit.
3. But if you don't have such a mass volume project and just don't want to write
your getter and setters then just type this prop + TAB+TAB
4. Remember you don't have to type all of this but you only type prop and then
press TAB two times for VS2008 to automatically generate the property for you
now you can change the name and any other thing by navigating and just
pressing TABS.
1. Select the code block for which you want to increase the indentation and after
selecting just press TAB, this will increase the indentation.
2. To decrease the indentation just select the required code block and then press
SHIFT + TAB, this will decrease the indentation of the selected code block.
Selecting a single word then line and then other lines within that block and
then.......
1. This is also a cool trick if you are in middle of something and want to do
something on either the word you are on or the entire code block, or entire
method, or entire class then just go on pressing Ctrl+W, it will start selecting for
you starting from the current word.
2. After selecting the desired code block you can perform any operation on
that code block.
5. Simply Press Alt+D+P then the Attach to process window will open.
6. Simply choose your web server process to attach and you will see
without building your entire solution your solution has been attached to the
debugger
Find Options
1. You are already familiar with Ctrl+F option to find something either in
current documents or all open documents or entire project or entire solution,but
another find option is Ctrl+Shift+F, this trick is helpful when you want all your
results to be listed in a find window rather then to navigate one by one in every file
where the searched string exists.
2. If you want to just toggle the markup's design and source view or want
to view both then press Ctrl+PageDown
Ctrl+TAB key will let you navigate between various open tabs in Visual Studio IDE
And press Ctrl+- to return back to the piece of code where you were earlier.
Selecting Source Control Plugin
1. If you are working in a team you probably will be using a source control there
are many options to choose SVN,Visual SVN,TeamFoundationServer,Source Vault and
Source Fortress and many others.
2. But when selecting a client you have to mention it in Source Cotrol Plugin
Selection as shown below
I want solution for every project which i create
1. If you want a solution for every project which you create then you have to
enable this as shown below
1. CTRL + "K" + "M":
Incase you need to add a method to an
already existing class you just write the method
as if it exists :
1: int i = 5;
2: bool flag = NewMethod(i);
2. CTRL + ".": This one expands the one before it, say you need to add a functionality
to a different class. again all you have to do is use the method as if it exists:
1: int i = 5;
2: bool flag = DifferentClass.NewMethod(i);
Put the cursor on the new method, click the shortcut and you will see this:
Hit Enter and you will get a new method stub with the return value and the parameter,
in the other class.
1: public class c
2: {
3: internal bool NewMethod(int i)
4: {
5: throw new NotImplementedException();
6: }
7: }
3. CTRL + "-" and CTRL + SHIFT + "-": These two are similar to the Forward and
Backwards buttons of the WebBrowsers and will take you to all the places your curser
was, Very useful for those times you click F12 to go to definitions and then have no
clue where you were before :).
4. ALT + ENTER: We talked about it in the last post, but it seems that this shortcut will
open the properties window on anything that moves, even Files in your Windows
Explorer.
5. SHIFT + ALT + ENTER: This one will switch you Visual Studio to Full Screen
mode, which is very useful in those boring presentation when you have to show your
code through a projector on a screen. Another click will get you back to normal mode.
6. CTRL + "M" + "M": This one will collapse the region your cursor is at whether its
a method, namespace or whatever for collapsing code blocks, regions and methods.
The first will collapse only the block/method or region your cursor is at while the
second will collapse the entire region you are at.
7. CTRL + ALT + "P": This will open up the attach to process window, very useful for
debugging.
8. CTRL + "R" + "R": This one is used to quickly rename a method/ variable or
whatever.
9. F8 and SHIFT + F8: These two are great! they are similar to the shortcut number 3
but they will take you forward and backwards in your search results just search for
something and then start hitting F8 and you will see.
10. CTRL + SHIFT + "B": This one will invoke build solution.
11. CTRL + "B" + "T": This one will allow you to quickly add or remove a bookmark
from a line of code.
ShortCut Description
Ctrl-X or Shift-
Cuts the currently selected item to the clipboard
Delete or Ctrl-L
Ctrl-Del Delete next "word"
Ctrl-C or Ctrl-
Copies the currently selected item to the clipboard
Insert
Ctrl-V or Shift-
Pastes the item from the clipboard at the cursor location
Insert
Ctrl-Z or Alt-
Undo the previous editing action
Backspace
Ctrl-Space To see intelligence dialog
Ctrl-Y or Ctrl-
Redo the previous undo action
Shift-Z
Ctrl-S Saves the current selected file
Ctrl-Shift-S Saves all files and projects
Ctrl-P Displays the Print dialog
F7 Switches from the design view to the code view in the editor
Shift-F7 Switches from the code view to the design view in the editor
ShortCut Description
Ctrl-End Moves the cursor to the end of the document
Ctrl-Home Moves the cursor to the start of the document
Displays the Go to Line dialog. If the debugger is running, the
Ctrl-G
dialog also lets you specify addresses or function names to go to
Moves the cursor to the matching brace in the document. If the
Ctrl-] cursor is on an opening brace, this will move to the corresponding
closing brace and vice versa
Ctrl-K, Ctrl-N Moves to the next bookmark in the document
Ctrl-K, Ctrl-P Moves to the previous bookmark
Ctrl-K, Ctrl-I Displays Quick Info, based on the current language
Scrolls text down one line but does not move the cursor. This is
Ctrl-Down
useful for scrolling more text into view without losing your place.
Arrow
Available only in text editors
Scrolls text up one line but does not move the cursor. Available
Ctrl-Up Arrow
only in text editors
Ctrl-Right
Moves the cursor one word to the right
Arrow
Ctrl-Left Arrow Moves the cursor one word to the left
Navigates to the next definition, declaration, or reference of an
item. Available in the object browser and Class View window. Also
Ctrl-Shift-1
available in source editing windows if you have already used the
Edit.GoToReference (Shift-F12) shortcut
Navigates to the previous definition, declaration, or reference of an
Ctrl-Shift-2
item
ShortCut Description
Shift-Tab Moves current line or selected lines one tab stop to the left
Backspace or
Deletes one character to the left of the cursor
Shift-Backspace
Ctrl-G Go to Particular line
Marks the current line or selected lines of code as a comment,
Ctrl-K, Ctrl-C
using the correct comment syntax for the programming language
Cuts all selected lines or the current line if nothing has been
Ctrl-L
selected to the clipboard
Deletes all selected lines or the current line if no selection has
Ctrl-Shift-L
been made
Ctrl-Enter Inserts a blank line above the cursor
Ctrl-Shift-Enter Inserts a blank line below the cursor
Shift-Alt-T Moves the line containing the cursor below the next line
Ctrl-M, Ctrl-P Removes all outlining information from the entire document
Ctrl-R, Ctrl-P Swaps the anchor and endpoint of the current selection
Ctrl-K, Ctrl-H Sets or removes a shortcut in the tasklist to the current line
ShortCut Description
Ctrl-Shift-B Builds the solution
Displays the New File dialog. Note: files created this way are
Ctrl-N not associated with a project. Use Ctrl-Shift-A to add a new
file in a project
Ctrl-Shift-N Displays the New Project dialog
Ctrl-O Displays the Open File dialog
Ctrl-Shift-O Displays the Open Project dialog
Shift-Alt-A Displays the Add Existing Item dialog
Ctrl-Shift-A Displays the Add New Item dialog
Allows you to override base class methods in a derived class
Ctrl-Alt-Insert when an overridable method is highlighted in the Class View
pane
Collapse all the methods, classes, regions in the current code
Ctrl-M-O
behind or class file
Expands all the methods, classes, regions in the current code
Ctrl-M-P or Ctrl-M-L
behind or class file
Ctrl-F Displays the Find dialog
Ctrl-H Displays the Replace dialog
Ctrl-Shift-F Find the reference of selected item into entire solution.
Move from one opened file to another opened file in visual
Ctrl-Tab
studio.
F9 Sets or removes a breakpoint at the current line
Enables or disables the breakpoint on the current line of code.
Ctrl-F9
The line must already have a breakpoint for this to work
F5 Runs the code with invoking the debugger.
Ctrl-F5 Runs the code without invoking the debugger.
Displays the Properties window, which lists the design-time
F4 or Alt-Enter
properties and events for the currently selected item
Displays the Server Explorer window, which allows you to view
and manipulate database servers, event logs, message
Ctrl-Alt-S
queues, web services, and many other operating system
services
Displays the Solution Explorer, which lists the projects and files
Ctrl-Alt-L
in the current solution
Displays the Toolbox, which contains controls and other items
Ctrl-Alt-X
that can be dragged into editor and designer windows
Displays the Immediate window, where you can find the
Ctrl-Alt-I controls or variables values or can do data manipulation during
debugging
If you are adding a new class in your code you may need to add the correspondence
namespace. To do it, you may either manually type the Using Namespace or you just right
click on the class name and select Resolve > Namespace. But using Ctrl+. you can
automatically add the namespace in your code.
Lets consider you want to add DataTable in your code, so for that you right click on that class
and select resolve to resolve the namespace.
But using Ctrl+. you can automatically add the using statement . See the below Image.
Fig : Add namespace using Shortcut key.
You can also generate the methods stubs using the same shortcut key. Like, If you want to
create method which will add to number, you can write like AddTwoNumber() and press
Ctrl+. and Enter to generate the Stub for your methods automatically
Like similar process that we have used for first two example you can implement all the
Interface or Abstract class using the same shortcut.
As for example you have a Class called student which Implement Interface IStudentInfo,
instated of manually implement all the properties or methods for the interface you can
generate the interface stubs automatically.
This is related with features 3. If you are trying to implement one Abstract Class or Interface
which is not created, by using this shortcut key you can create the file automatically. You do
not need any manual process to add the file. By using Ctrl+. and Enter a class files with
the same name will be automatically added in App_Code Folder.
By using the same key Ctrl+. you can also rename the same referenced variable at a time
in all over the application.
Bookmarks
For keystrokes with two keys such as Ctrl+k+k, keep holding the Ctrl key
until releasing the last key.
Ctrl+K+K Toogle bookmark
Ctrl+K+N Goto next bookmark
Ctrl+K+P Goto previous bookmark
Ctrl+Shift+K+N Goto next bookmark in folder
Ctrl+Shift+K+P Goto previous bookmark in folder
Ctrl+K+W Put focus on bookmark window
Esc Leave bookmark window and focus on editor
Ctrl+K+H Toggle code shortcut at current line*
Ctrl+K+L Clear all bookmarks
Ctrl+\+T Show Task List (including code shortcuts)
*if somebody figures out additional shortut keys on how to use code
shortcuts, please edit this page and add.
Code Editor
Select Text
Shift+Arrow Keys Extend selection one character/one line
Ctrl+Shift+End/Ctrl+Shift+H Extend selection to end / to beginning of
ome document
Ctrl+Shift+] Extend selection to nexst brace
Extend selection to end / to beginning of
Shift+End/Shift+Home
line
Shift+Page Down/Shift+Page Extends selection down one page / up one
Up page
Ctrl+W Select current word
Esc Cancel Selection
Ctrl+Shift+Page Down/Page Moves cursor and extend selection to the
Up last line / first line in view.
Ctrl+Shift+Arrow Right/Arrow Extend selection one word to the right / one
Left word to the left
Ctrl+A Select All
Coding
Collapse Items
Edit Code
Delete current line or selection of lines to and add to
Ctrl+L
clipboard
Ctrl+Shift+L Delete current line or selection of lines
Ctrl+Delete Delete word to right of cursor
Ctrl+Backspac
Delete word to left of cursor
e
Ctrl+Enter Enter blank line above cursor
Ctrl+Shift+Ent
Enter blank line below cursor
er
Ctrl+Shift+U Make uppercase
Ctrl+U Make lowercase (reverse upercase)
Ctrl+K+C Comment selected text
Ctrl+K+U Uncomment selected text
Remove white space and tabs in selection or around
Ctrl+K+\
current cursor position
Ctrl+K+D Format document to code formatting settings
Ctrl+K+F Format selection to code formatting settings
Ctrl+Shift+Sp
Display parameter required for selected method
ace
Ctrl+Shift+8 Visualize whitespace (or press Ctrl+r, then Ctrl+w)
Ctrl+K+D Format document to code formatting settings
Ctrl+K+F Format selection to code formatting settings
Transpose word to right of cursor; makes b=a out of a=b if
Ctrl+Shift+T
cursor was in front of a
Transpose character left and right of cursor; cursor
Ctrl+T
between ab would make ba
Transpose line: Move line below cursor up and current line
Shift+Alt+T
down.
Tool Windows
http://visualstudioshortcuts.com/2013/