Knowing how to use default code snippets in .NET is really beneficial for any programmer. Code snippets are pre-written codes in .NET which programmer can quickly insert using shortcut keys. This makes programmer’s job easy by not having to retype frequent reused structures of code.
Code snippets are an excellent way to accelerate your coding. Most frequently used code constructions are included. I’ll use MessageBox in my first sample.
Whenever you need to use MessageBox.Show method, you write the entire one line code like this:
But using default Code Snippets you could save time and build more productivity.
Type ‘mbox’ and press Tab key twice, and the Visual Studio IDE will fill in MessageBox.Show method for you.
Let us try another. Type ‘for’ and press Tab key twice. IDE will generate the loop syntax automatically.
for (int i = 0; i < length; i++)
Like this way, you can use the following default code snippets.
These are the available Code snippets in Visual Studio IDE.
#if Creates #if and #endif directive. #region Creates #region and #endregion directive. ~ Creates a Destructor. attribute Creates a declaration for a class that derives from Attribute. checked Creates a checked code block. class Creates a class declaration. ctor Creates a constructor. cw Creates a Console.Writline code block. do Creates a do while loop. else Creates an else code block. enum Creates an enum declaration. equals Creates a method declaration that overrides the Equals method. exception Creates a declaration for a class that derives from an exception. for Creates a for loop. foreach Creates a foreach loop. forr Creates a for loop with decrementing loop variable. If Creates a if block. Indexer Creates an index declaration. Interface Creates an interface declaration. Invoke Creates a block that invoke an event. Iterator Creates an iterator. Iterindex Creates a "named" iterator and indexer pair by using a nested class. lock Creates a lock block. mbox Creates a call to MessageBox.Show method. namespace Creates a namespace declaration. prop Creates an auto-implemented property declaration. propfull Creates a property declaration with get and set successors. propg Creates a read-only auto-implemented property with a private "set" accessor. sim Creates a static int Main method declaration. struct Creates a struct declaration. svm Creates a static void Main method declaration. switch Creates a switch block. try Creates a try-catch block. tryf Creates a try-finally block. unchecked Creates an unchecked block. unsafe Creates an unsafe block. using Creates a using directive. while Creates a while loop.