Tricks And Tips In Visual Studio To Speed Up Your Code Using Default Code Snippet Feature

This article explains few features which will helps to developer to speed up coding while writing code in visual studio.

In this small article, I will explain the default code snippet feature which helps developers to speed up coding while writing their code in Visual Studio. Many of us are aware but some beginners may not be aware of the code snippet feature of Visual Studio which is a really cool inbuilt feature of Visual Studio. This looks very small but it helps in the long run.
 
Let's take a few code snippet examples which we are using in day to day activity while writing the code like prop, propfull, class, ctor, cw, for etc. I will explain a few of them in details. I will list down a few snippets which we use as a regular day to day activity.
 
Class creates a class declaration
ctor creates a constructor for class
propcreates an auto-implemented property declaration.
propfull creates a property decalration with get and set accessor
propg creates a read only auto implement a property with private set accessor
cw creates console.writeline()
do creates do while loop
for creates for loop
foreach creates a foreach loop
svm creates static void main method declaration
switchcreates a switch statement
trycreates try block
trytry block with finally clause
whilecreates while loop
 
Let's try some of the above default code snippets. First, we will start with property code snippet and understand how to use it in the day to day activity. 
 
Property
 
In general, if we create a property in the class, then we will write it like below.
  1. public class Employee  
  2. {  
  3.     public int EmployeeId { getset; }  
  4. }  
In the above example, we wrote property by typing everthing but how can we achieve this using code snippets?

Just type "prop" and hit Tab key twice to insert 'prop' snippet. You are able to see it in the code's right side after hitting Tab key twice. 
 Visual Studio
Full property
 
If I want to create full property, then I have to write the below code manually but by using the propfull code snippet, we can speed up our code.  
  1. private string firstName;  
  2.   
  3. public string FirstName  
  4.  {  
  5.      get { return firstName; }  
  6.      set { firstName = value; }  
  7.  }  
 Visual Studio
Constructor
 
Let's create a constructor by writing the code manually. 
  1. public class Employee  
  2.  {  
  3.      public Employee()  
  4.       {  
  5.   
  6.       }  
  7.  }  
But if we use a code snippet to create a constructor, we need to type ctor and hit the tab key twice. Our constructor is ready and there is no need to type the code manually.
 
 Visual Studio
 
Console.WriteLine 
 
Like the above code snippet, if we want to write Console.WriteLine, then we have to use cw code snippet and perform the same step like type cw and hit tab twice and it will create Console.WriteLine() for you.
 
Visual Studio 
Now, I am not going to explain each code snippet because for every code snippet we need to follow the same thing. Here, l will give a screenshot of how can we identify which are the code snippets available in Visual Studio. Please look at the below snippet; there, I have marked it with an orange circle and pointed to it with the arrow. Once you see square box while typing it means it is the code snippet. 
 Visual Studio
If we try to use the above default code snippet while writing the code that will really help us to write the code more efficiently. I started following this for the last two years and I am able to see a difference now. I hope you also try this if you haven't yet.
 
Thanks for reading.
 
I hope it will help someone.
 
Click Here  to refer my blogs and articles.