|
May 23, 2002 Using Qualified Class Names Tips: May 2002
Yehuda Shiran, Ph.D.
|
|
When you import several namespaces
in your code, and you reference a class member (a property or method), there is
always the question from which namespace this class is referenced. The compiler
first searches the local scope. If it doesn't find the class, the compiler searches
the classes in each of the imported namespaces, in the order they were imported,
and stops when it finds a match.
You can control the namespace you want to reference by using a fully qualified name. Here is an example:
Assuming several namespaces include
different types of the Queue
class, you can use the fully-qualified name to force usage of an explicit namespace,
the System.Collections namespace.
But if you know that the class Queue
is defined only once in all imported namespaces, you can use a shorter non-qualified
name:
You can mix fully-qualified and
non-qualified class names. The advantage of fully-qualified names is that the
code is much easier to debug because you know exactly where the classes reside.
To learn more about JScript .NET, go to Column 109, JScript .NET, Part III: Classes and Namespaces.
People who read this tip also read these tips: Look for similar tips by subject: |