views:

155

answers:

3

I type

ArrayList memberNames = new ArrayList() { "Jim", "John", "George" };

and Visual Studio tells me "ArrayList" cannot be found so I have to manually go to the top of the file and type

using System.Collections;

Is there a way to get Visual Studio to do this automatically?

In FlashDevelop, for instance, you press CTRL-SHIFT-1 and it automatically generates these missing references, a nice feature.

+4  A: 

SHIFT-ALT-F10 Will activate the Smart Tag on the class, which will give you the options "using System.Collections", and "System.Collections.ArrayList". It's typically two keystrokes to add a using.

Edit: Seems I had a mangled keyboard profile. Updated the key combo to the default. Thanks to Alan for pointing it out.

ckramer
Funnily, people upvoted this without even trying the key combo. It's Shift+Alt+F10 (the one given here is for the editor context menu) by default, at least in the Visual C# keyboard layout. ckramer, can you please edit your answer?
Alan
+2  A: 

Alt-Shift-F10 brings up a pop-up menu with "using System.Collections", and "System.Collections.ArrayList".

If you want to find a keyboard shortcut, choose Tools: Options and navigate down to Environment: Keyboard. However, it can be a challenge to figure out what they've called the thing you're looking for. (The one you asked about is obviously View.ShowSmartTag, right?)

Update: From comments and other posts, I just learned that Ctrl-. also brings up the same menu. I guess not all the keyboard shortcuts appear in the keyboard options dialog.

Don Kirkby
Ctrl-. also brings up that menu.
Alexander Prokofyev
Cool, I didn't know that.
Don Kirkby
+1  A: 

CTRL+. also activates the Smart Tag, which might be more intuitive.

Bryan Watts