Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 - fix "using" feature? [duplicate]

Is there any way to fix "using" in my C# file? I looking for some sort of "fix (organize) imports" from NetBeans or Eclise for java. I looking for the easiest way to fix issue: "The type or namespace could not be found" when I miss some "using" directive. Actually, I do not remember all C# classes hierarchy.

like image 372
Eugeny Avatar asked Dec 12 '22 15:12

Eugeny


2 Answers

When you type the name of a type which isn't already imported, it will be highlighted in red. If you press Ctrl-period, Visual Studio will offer to import it. (There should be a blue dot near the cursor to indicate this as a possibility.) Or using ReSharper, press Alt-Enter on the line with the problem.

Note that that only tackles the "adding a using directive" side of things. There's also the "Remove and sort using directives" command for keeping things tidy. I typically having that bound to Ctrl-Shift-U, but I don't think it has a shortcut by default.

like image 119
Jon Skeet Avatar answered Jan 01 '23 13:01

Jon Skeet


If you have the necessary assemblies referenced, you can right click (or hover) on an unrecognized class name to find a "Resolve" submenu to help you. You can find options to add necessary usings or change the class name to fully qualified with namespaces in your code.

like image 23
zsgalusz Avatar answered Jan 01 '23 13:01

zsgalusz