Friday, August 23, 2013

Working with Code Snippet

If you are working with Visual Studio IDE for c#/vb then you came across a situation where you need to write down a same line of code at many place.

Here is the way how you can save your time from writing same line of code again and again.


(1) Write it down on "General" Tab of your Toolbox
- if you are aware of toolbox then you probably knowing tabs under this toolbox. In Toolbox, for HTML view you will find different controls available in tree view style and tabs are like "Standard", "Data", etc.. are available (below screenshot).

- You will find one more tab that is "General". In general tab you can save your frequent line of code so that whenever you require them you can easily search from this Toolbox and get those line of code you require (Keyboard shortcut for Toolbox is Ctrl + Alt + X).To do this, just copy line of code you require frequently and paste that under "General" Tab of "Toolbox" and Once you paste, it will appear under your "General" Tab (below screenshot).



You can rename its title so that it will be easily searchable code for your reference. Once you paste this line of code, you will be able to see this at both "HTML" and "Code Behind" Toolbox view and use this line of code at both places.

(2) Use Code Snippet
Visual Studio provides code snippets in built so that you can use some code samples and you are not need to write that line of code.

To use Code Snippet just write down short name used for that snippet. So, let say you are about to create new property then write "prop" and hit "Tab" key and it will automatically insert line of code for property.


You will find some links from my previous post for Code Snippet in Visual Studio.

No comments:

Post a Comment