Use Ctrl+. (period) to trigger Visual Studio’s automatic add using statement context menu

When you type class names that are missing the correct namespace reference, Visual Studio will help you out by giving you a context menu that you can use to automatically add the correct using statement to the top of your class.

For instance, in the example below, the Utility class exists in a different namespace that is not currently referenced in the class.  Visual Studio gives you the red squiggly to show there is an error but there also is a small little line at the end of the class name:

image

You can take your mouse and hover just over that line and you will get a little drop-down context menu:

image

Which is a very nice feature where Visual Studio will automatically add the using statement to the top of your file (or insert the full reference):

image

The feature to add the using statement to your class is great in itself but getting your mouse into just the right spot to click that little line is pretty tricky (and also can break your development train of thought). 

As the tool tip says, you can hit Shift+Alt+F10 to get the context menu but Ctrl+. (period) will also pop up that menu and it is a much easier key combination to use.



No Comments