Re: The :: operator, and "global"
- From: Oliver Sturm <oliver@xxxxxxxxxxxx>
- Date: Sat, 20 Aug 2005 12:50:35 +0100
Javaman59 wrote:
I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNamespace
I hadn't seen this before, so looked it up in MSDN, which explained it nicely. My question is, do "global" and "::" always go together? Is there any other use for these operators, than as a pair?
Apart from the other replies, there's another, maybe more common, use for the :: operator. You know the way you can define aliases in a using statement? Like this:
using SWF = System.Windows.Forms;
Now you can use SWF as a shortcut for the System.Windows.Forms namespace. In .NET 1.1, you used to write
SWF.Form
or whatever to refer to a type within the aliased namespace. This could obviously be an ambiguous expression in certain circumstances, so in ..NET 2, the :: operator was introduced to be used in this situation. So in .NET 2 you'd write
SWF::Form
instead, which is no longer ambiguous. The "global" alias is nothing more than a default alias for the topmost namespace and can't be used in any other context, as the other posters already said.
Oliver Sturm -- omnibus ex nihilo ducendis sufficit unum Spaces inserted to prevent google email destruction: MSN oliver @ sturmnet.org Jabber sturm @ amessage.de ICQ 27142619 http://www.sturmnet.org/blog .
- Follow-Ups:
- Re: The :: operator, and "global"
- From: Javaman59
- Re: The :: operator, and "global"
- References:
- The :: operator, and "global"
- From: Javaman59
- The :: operator, and "global"
- Prev by Date: Re: static virtual/override
- Next by Date: Re: Timing Question
- Previous by thread: Re: The :: operator, and "global"
- Next by thread: Re: The :: operator, and "global"
- Index(es):
Relevant Pages
|