spacer
Yehuda Shiran May 23, 2002
Using Qualified Class Names
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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:

  import System.Collections;
  var my_queue : System.Collections.Queue;
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:

  import System.Collections;
  var my_queue : Queue;
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:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business