How to store and use reusable code from Visual Studio tool box

Coding Coding Best Practices How to guide

Microsoft Visual Studio provides powerful features helping in rapid code development and make developer productive. In this article introducing one such feature that reduce expensive copy-paste operations when there is a same piece code snippet to be reused in multiple code blocks. Yes, it’s about how to store and use reusable code from Visual Studio tool box.

For example: Suppose if you need to add trace log related code in each code block then most of the time you copy the existing line of a code which was already written in some code file. Copy and past operation is little bit expensive when there is a common code to be written across the project.

Store and use reusable code from Visual Studio tool box:

In Visual Studio, you can keep this peace of code in the tool box and you can reuse this code when required. You just need to drag and drop the code line from the tool box to your code editor pane. This is similar to drag drop Button control to form.

Follow the below steps to see how to move code snippet into tool box in Visual Studio.

1 In Visual Studio Code editor, select the most reusable code snippet. once the selection made, drag and drop that code into Tool box pane. The code snippet gets added into toolbox under general group.
2 On the tool box, select the code snippet item and right click to open the context menu. On the context menu, select Rename menu item. Now, the code snippet item in the tool box becomes editable. Rename this item to some name through which you can identify what code is inside.
3 Once renamed, drag and drop the code snippet item from the tool box to code window. The respective code snippet will be copied at the position where the cursor blinking. You can do this any number of times when ever this piece of code is required in your project.
This is really help developer to minimize most costliest operation such as copying the reusable code from one code file and use it. Here you can watch entire steps in one Video.

– Article ends here –

Related Tags:

Software engineer by profession, founder of troubleshottyourself channel and enthusiastic blogger. Love to write articles on new technology, programming,

Share this: