How to: Find out which namespace contains a certain object or class
We have all been in that situation where you want to use a specific class or object, but you just can't remember which namespace to use. Visual Studio can help you find that namespace.
Visual Studio 2003 and 2005
Both versions of Visual Studio support the key-combination Alt+Shift+F12. For example: You want to use StreamWriter and you cannot for the world remember in which namespace you can find that class. What you do is this:
- Place the cursor on the text StreamWriter in your code window.
- Press and hold the keys Alt+Shift+F12.
You will see a window somewhere on the screen which shows the results. For StreamWriter you will see the following results:
And what a surprise, StreamWriter is in the System.IO namespace. This will work for both C# and VB.Net. This option is not case sensitive, so you can type StreamWriter, or streamwriter. It will find the symbols for you.
Visual Studio 2005
This version of Visual Studio has an even better option. In this version you have the key-combination Alt-Shift-F10. Let's use the StreamWriter class again as our example. Follow this steps:
- Place the cursor on the text StreamWriter in your code window.
- Press and hold the keys Alt+Shift+F10.
What happens is that Visual Studio 2005 will display a drop-down selection menu next to your cursor, as you will see in this image:
As you can see, Visual Studio presents two options. The first option, which is the default option, will add a using System.IO; line to the code. The second will change the StreamWriter code to read System.IO.StreamWriter. What ever you prefer. Strangely enough, I only saw this work in C#. But feel free to correct me if I'm wrong. Unfortunately, this option is case sensitive.
One (big) but...
Visual Studio will only search assemblies that are referenced for object or class you're trying to find. But usually, most assemblies you need are already referenced. If these options do not find the reference for you, you will have to check MSDN. Or check the documentation of your third-party libraries.