« Using methods that get passed (Generic) delegatesI feel colour blind... »

global, ::, huh?

20/08/05

Permalink 06:56:45 pm
Categories: General, Programming, .NET

global, ::, huh?

I guess you know the way you can define aliases with the using statement:

using SWF = System.Windows.Forms;

Then you can use the shortcut SWF to reference a type in the namespace. In C# 1, the syntax was like this:

SWF.Button button = new SWF.Button();

Obviously this could be ambiguous, because there could have been any kind of different identifier in scope called SWF. To get rid of this ambiguity, C# 2 introduced the :: qualifier. So now you'll write the same thing differently:

SWF::Button button = new SWF::Button();

So, the identifier to the left of the :: qualifier (called the namespace alias qualifier, by the way) defines the namespace that is searched for the identifier to the right of the qualifier. This is where global comes into play: this is an identifier you can use if you want to look only at the global namespace. For example, to make absolutely sure that a reference to a class called String can only ever mean (the framework standard) System.String, you could put something like this:

global::System.String mystring = new global::System.String('x', 10);

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
Please complete the song title below. Hint: enter 'h', 'e', 'a', 'v', 'e', 'n'
antispam test

Enter your email address:

Search

Oliver
MVP logo
July 2010
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31