New Features in C# 2.0—Global Namespace: What just happened?

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:Tutorials
C# Tutorials

New Features in C# 2.0

© 2005 O'Reilly Media, Inc.

How do I do that?

In this somewhat artificial example, you create a nested class that you named System and you created a local Boolean variable named Console. You have blocked access to the global System and Console identifiers, so neither of these lines will compile:

Console.WriteLine(x);
System.Console.WriteLine(x);

To designate that you want to use the System object in the global namespace, you will use the global namespace qualifier:

global::System.Console.WriteLine(x);

Notice that in the final line, the global namespace qualifier is used to access the System and Console objects in the global namespace, and the unqualified Console identifier is used to access the local Boolean value:

global::System.Console.WriteLine(Console);


Previous_Page_.gif Next_Page_.gif


Personal tools