Share via


Add using

Add using is a Visual C# IntelliSense feature that provides an easy way to search for the namespace that declares an unbound type that is present in your code, and then add a using directive for that namespace to your code or fully qualify the instance of the unbound type.

Remarks

An unbound type is a type referenced in the project that IntelliSense and the C# compiler cannot match to a declaration. Referencing the namespace that declares the type, as with a using directive, enables IntelliSense and the compiler to read the type.

If an unbound type is nested in multiple namespaces or types, IntelliSense displays more than one suggestion about what to bind the unbound type to. The maximum number of suggestions that IntelliSense can display at a time is five using statements and five fully qualified names.

The Add using IntelliSense operation enables you to maintain your focus on the code you are writing rather than requiring you to shift your focus to another part of the code.

To initiate the Add using operation, position the cursor on a type reference that cannot be resolved. For example, when you create a console application and then add XmlTextReader to the body of the Main method, a smart tag will appear under the rightmost character of XmlTextReader, since it appears as a type reference that cannot be resolved.

Add Using Smart Tag Image

You can then invoke the Add using by selecting it from Resolve submenu of the IntelliSense menu or the context menu, or by invoking Add using through the smart tag. The smart tag is only visible when the cursor is positioned on, or adjacent to, the unbound type.

Add using, smart tag expanded image

When you invoke the Add usingoperation, the using directive is added to the beginning of the source code. For more information, see How to: Add using for Unbound Type.

See Also

Reference

using Directive (C# Reference)

Concepts

How to: Create Solutions and Projects

Other Resources

Automatic Code Generation