Snippet Functionality in Visual Studio

There are two types of snippets.

1. Insert Snippet

This option in Visual Studio is very useful for inserting quick code snippets at the cursor position.

This functionality helps us in entering a block of code like a foreach structure or class and so on in the code.

for inserting quick code snippets

Right-click on your code where you want to insert the code snippet and select the “Insert Snippet” option.

Right click on your code

Select the snippet you wish to insert. For example select foreach as in the following:

Select foreach

A foreach block will be added and you can now customize it.

Similarly you can add other snippets too.

2. Surround With Snippets

This is used to wrap the selected code into a region

This functionality is used to group your code, to make it cleaner and readable.

Select the code you want to group and right-click and select the Surround With option.

Surround With Snippets

Surround With

You can select any of the preceding to group your code. For example select #region

region

#region MyRegion group your code. You can rename the region. Similarly you can use other groups.

Up Next
    Ebook Download
    View all
    Learn
    View all