Code snippets are small blocks of reusable code that can be inserted in a code file using a context menu command or a combination of hot-keys. They typically contain commonly-used code blocks such as try-finally or if-else blocks, but they can be used to insert entire classes or methods.
List of Visual Studio snippet shortcuts:
#if– Creates an
#ifdirective and an
#region– Creates a
#regiondirective and an
~– Creates a destructor for the containing class.
attribute– Creates a declaration for a class that derives from
checked– Creates a checked block.
class– Creates a class declaration.
ctor– Creates a constructor for the containing class.
cw– Creates a call to
do– Creates a
else– Creates an
enum– Creates an
equals– Creates a method declaration that overrides the
Equalsmethod defined in the
exception– Creates a declaration for a class that derives from an exception (
for– Creates a
foreach– Creates a
forr– Creates a
forloop that decrements the loop variable after each iteration.
if– Creates an
indexer– Creates an indexer declaration.
interface– Creates an interface declaration.
invoke– Creates a block that safely invokes 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
System.Windows.Forms.MessageBox.Show. You may need to add a reference to System.Windows.Forms.dll.
namespace– Creates a
prop– Creates a property declaration and a backing field.
propg– Creates a property declaration with only a “
get” accessor and a backing field.
sim– Creates a
static int Mainmethod declaration.
struct– Creates a
svm– Creates a
static void Mainmethod declaration.
switch– Creates a
try– Creates a
tryf– Creates a
unchecked– Creates an unchecked block.
unsafe– Creates an
using– Creates a
while– Creates a