Code Rewind
When its time to find, Hit Rewind
                 
 
 
Remember Me  
Recover Password
 
 Advanced Search
 
 Add to IE Search 
 
 
> Development > Application Development > Languages > .NET => How to use Namespace Alias Qualifier - (global)
 

Available Files:
You must be signed in to download files.
You can Sign Up here if you are not a member.
Author: Binoj Daniel
Level: 3
Date Posted: 09-Dec-2008 (08:25)
Last Updated: 09-Dec-2008 (08:28)
Views: 1,221
Favorited: 0
Votes:
  -  1 votes
Your vote:
Click to rate Click to rate Click to rate Click to rate Click to rate
(5 Stars)
Rating: 5.00 out of 5


Summary: As you know a code file can declare multiple namespaces - stand-alone ones or nested ones. The types under the namespaces with the same name are treated as one single logical group. Types that are not declared in any namespace are considered to be in the “global” namespace, which is the outer-most, default one.

Elaboration:
Suppose you define a namespace TestModule and also define a class with the same name inside it as shown in the example below:

namespace TestModule
{  
    class TestClass
    {
        class TestModule { }
        TestModule.TestClass test = new TestModule.TestClass(); 
    } 
}

When you try to instantiate “TestClass” qualified with the namespace name “TestModule”, the compiler will give an error saying: “The type name 'TestClass' does not exist in the type 'TestModule.TestClass.TestModule'”. This happens because the class “TestModule” which is inside hides the namespace “TestModule” which is at the global level.

The external alias global(C#)/Global(VB.NET) can be used to resolve conflicts between namespaces and hiding inner types as shown below:

namespace TestModule
{  
    class TestClass
    {
        class TestModule { }
        global::TestModule.TestClass test = new global::TestModule.TestClass(); 
    } 
}

When the “global” alias is used, the search for the right-side identifier starts at the global namespace which is the root level of the namespace hierarchy. This helps to resolve the type from the outer most level (global level) drilling inwards.

The chances for such conflicts can be avoided to a good extent by following proper naming standards. But when huge class libraries and third-party components are used this situation can arise. In such cases the usage of namespace alias qualifier can save a lot of time!! 

Version Tracking:

Version 1.0
 
KeyWords: Generic / None,VB.NET,C# (Generic / None);Generic / None,.NET Framework (Generic / None);Generic / None (Generic / None);
CR Suggested .NET Articles
 
Multi-Threading in .NET by it2max (09-Aug-2007)
 
Most Recent Views
 
About .NET Framework Versions by Guest (08-Sep-2010 03:19)
How to get details of a file extension including icon by Guest (08-Sep-2010 03:17)
What happens to the .NET Code you write? by Guest (08-Sep-2010 03:15)
Using Trusted Connections & Impersonation in Web Applications by Guest (08-Sep-2010 03:07)
Windows Presentation Foundation (WPF) Part 2 by Guest (08-Sep-2010 02:39)
 
 Messages: 0, Topics: 0. Post New Message Please login to post a message...
  View
Items per page
Message since
  TOPIC
AUTHOR
VIEWS
REPLIES
LAST POST
No messages boards...

Post New Message      
General Comment News / Info Question Answer Joke / Game Admin Answer
SEARCH ON FORUM
 
 
   
 
 
TOP USERS
 
No top users
 
 
TOP DISCUSSIONS
 
No popular discussions
 
 
SPONSORED ADS
 
 
 
 



 
Registered Members: 1621
Now Browsing: 2
 
Subscribe to newsletter
 
 

 
IT2Max
TheBusinessXP
RapidConvert
AtHomeTution
 








 
About Us  |  Contact Us   |  Privacy Policy  |  Legal Notice  |  Terms and Conditions  |  Help   |  Browse CR   |  Articles  |  Webcasts  |  Ask an Expert   |  Message Boards   |  Downloads  |  Open Arena   |  FAQ | DaniWeb | GetAHelpdesk | ProgTalk
Copyright © 2007 CodeRewind.com. All rights reserved
designed by IT2Max, INC.
 
Execution Time: 1.93 sec