Automatic namespaces import

Visual StudioImportKeyboard ShortcutsHotkeys

Visual Studio Problem Overview


Is there a way in Visual Studio (a hotkey) to automatically import a type (or choosing between known namespaces) like the Ctrl + O in Eclipse?

Visual Studio Solutions


Solution 1 - Visual Studio

Yes, Visual Studio can add the using for you. When you type in a class name, hit Ctrl + . and then Enter (the first option is 99.99% the right one, so just hit Enter). And you can have it add the using at the top of the file for the namespace of that class. I use it all the time.

This is easier than Shift + Alt + F10 + Enter as it's fewer keys and the . and Enter are closer.

Solution 2 - Visual Studio

When the red caret appears at the end of your member, just hit Shift + Alt + F10, then use arrows keys to choose the right option:

Enter image description here

Solution 3 - Visual Studio

Look at JetBrain's excellent ReSharper product. It does this for you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEnrico MurruView Question on Stackoverflow
Solution 1 - Visual StudiomattlantView Answer on Stackoverflow
Solution 2 - Visual StudioLarryView Answer on Stackoverflow
Solution 3 - Visual StudioAndrewView Answer on Stackoverflow