views:

279

answers:

7

I often find myself remembering the name of a class that I want to use, but not remembering the containing namespace. Apart from searching the web, i wonder if a good method exists for looking this up.

+1  A: 

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

S.C. Madsen
+1  A: 

I generally use the offline MSDN reader, with the left panel set to the Index tab.

Another option in Visual Studio is to type the name of the type as if you were declaring a variable, and then see what it suggests. If the name goes to a light blue colour (by default) then it's in one of the namespaces you're already importing - just hover over it to find out which. Otherwise, see what namespaces it offers to add using directives for.

Jon Skeet
Good idea too, can the MSDN reader be configured to only show class names?
S.C. Madsen
I don't think so - although filtering it to "Visual C#" helps a bit.
Jon Skeet
+6  A: 

I think if you press ALT, SHIFT and F10 in Visual Studio - intellisense will drop down an option for you to add the name space of the class you have just typed.

Chalkey
Brilliant! I cannot tell you how helpfull I think this is. Thanks!
S.C. Madsen
I use this all the time. I just wish it had another option to use the form `using Path = System.IO.Path;` instead of just `using System.IO;` or placing `System.IO.Path` at the current location.
280Z28
Or a little more comfortably on the keyboard: Ctrl-Period
Jon Skeet
@John Skeet - never knew that! Although my fingers cant seem to undo the years of stretching for the F10 key!
Chalkey
+2  A: 

You can always hang a big poster on your cube wall like me.

3.5 NameSpace

J.Hendrix
MS should ship a full size version of this poster to it's MSDN subscribers...
Philip Wallace
+1 I agree. I subscribe to Tech Net magazine (Don't pay for it. You can usually get it for free). It will sometimes come with cool/useful tech posters like this. But have not seen the namespace one in there yet. I keep hoping to replace mine with a nice professionally printed one.
J.Hendrix
A: 

You can right click and select "Go To Definition" in VS and this will either load the class definiftion in your solution or it will show a metadata view of the class definition using reflection. Either of those should have the namespace defined near the top of the page.

If you need to add the namespace with a using decliration right click the unresolved class and mouse over to resolve. It will show you a list of namespaces that contain that class and selecting one will generate the using statement.

OrionRobillard
I just tried this, and it does not work if the type is not already within scope (is it called scope?). I got an error: Cannot navigate to '<class name goes here>'
S.C. Madsen
Yeah sorry, I you were asking something else. Go to definition only works if you have already declared the namespace. Right clicking and using the resolve menu is just another way of doing the alt-shift-F10 trick.
OrionRobillard
+3  A: 

CTRL + '.' will bring up a menu where you can either add a 'using' or fully qualify the class.

Philip Wallace
That's great, especially the ability to auto-insert the 'using', nice!
S.C. Madsen
+1  A: 

If you know the name of a class in .Net but have no idea what namespace it is in, it can be hard finding it, especially if you dont have a reference/using to the assembly containing it.

This is where the Object Browser (Ctrl+W,J) comes in handy.

Open it up, type in the name, it will give you all matches, either within your project/solution, or all of the .Net framework.

Edit:
As S.C. Madsen's comment points out, this also helps if you only remember PART of a class name, also if you only remember a method name but not the class.

Neil N
Didn't know that one either. I think this one is especially usefull if you only remember part of the class name.
S.C. Madsen