Skip to content

Visual Studio Tips and Tricks

I have been using Visual Studio over a decade almost daily and I would like to share few tips that I find particularly useful and which improves your productivity if used correctly.

Surround with

Select code that block that you would like to surround with and then press CTLR+K, CTRL+S. This starts and macro that can used to surround blocks of code with try-catch, using, etc. I use this macro mainly for try-catch blocks, but it is rather useful for other use cases also.

Add missing using directives on paste

In the Visual Studio options there is a C# setting to put using directives in place automatically when the code is pasted. The added directives are based on the normal VS intellisense, so it does not add nuget packages into project or anything like that. Usually what I want from this feature is the System.Collection and System.LINQ kind of directives that should be placedd automatically.

Paste JSON As Classes

Sometimes you receive an example of JSON data that is served from REST API and you don’t have Swagger documentation available. In those scenarios I use the Paste Special command to create me a classes of the JSON data structure. You try this feature by copying an example JSON from https://www.json.org/example.html and then use the edit menus Paste Special functionality to create classes.

Immediate Window

The Immediate Window is something that junior developers usually don’t know about. The window can be toggled on from Debug > Windows > Immediate menu. Immediate Window can be used during debugging to set and query variables, invoke methods and much more. I usually use it during debugging to change the value of the variables. The value change is simply done by writing normal assignment statement. For example

test = 20

The variable value can be queried with ?(variable name) syntax. For example ?test.

I hope you learned something new from these Visual Studio tips. If you have any other tips to share, please use the Contact page to write me a message and I will apply your tips into this list.