C # /. NET How to find containing namespace from class name

I often recall the name of the class that I want to use, but I don’t remember the containing namespace. Besides searching on the Internet, I am wondering if there is a good method for finding this.

+6
c # visual-studio
source share
8 answers

I think that if you press ALT, SHIFT and F10 in Visual Studio, intellisense will lay out the option to add the namespace of the class you just typed.

+16
source share

CTRL + '.' will open a menu where you can either add “use” or fully qualify the class.

+7
source share

You can always hang a large poster on the wall of your cube, like me.

3.5 NameSpace

+4
source share

Use the search function in the .NET Reflector from Red Gate Software.

+1
source share

I usually use a standalone MSDN reader, and the left pane is set to the Index tab.

Another option in Visual Studio is to enter a type name as if you were declaring a variable, and then you see what it offers. If the name changes to a light blue color (the default), then it is located in one of the namespaces that you are already importing - just hover over it to find out which one. Otherwise, see what namespaces it offers to add using the directives for.

+1
source share

You can right-click and select Go To Definition in VS, and this will either load the class definition in your solution or display the metadata in the class definition using reflection. Any of these must have a namespace defined at the top of the page.

If you need to add a namespace using the declaration, right-click on the unresolved class and hover to resolve. It will show you a list of namespaces that contain this class, and selecting it will generate a using statement.

+1
source share

If you know the class name in .Net, but don’t know in which namespace it can be found, it can be difficult to find, especially if you don’t have a reference / use for the assembly containing it.

It is convenient to use the object browser (Ctrl + W, J).

Open it, enter a name, it will give you all the matches, both within your project / solution and throughout the .Net infrastructure.

Edit:
As SC Madsen notes, this also helps if you only remember the PART of the class name, also if you only remember the method name, but not the class.

+1
source share

Two ways to work in Visual Studio 2013:

  • Right-click and select Allow.
  • Hover over the class and the "Options to help bind selected item" box appears (same as Ctrl + "." Or Alt + Shift + F10)

Select a namespace and paste it for you.

0
source share

All Articles