Proper use of global:: (or Global.)

Written by Sameer on June 8, 2007 in: .NET articles |

The C# keyword global:: (also known as Global.) allows .NET to differentiate between two namespaces.

Say you have a namespace called Common, and you have a class called Setup

In that case, to refer to a function inside it called GetUsersOnline(), you would write Common.Setup.GetUsersOnline()

 However, say that you are currently working within the Accounting namespace, and the accounting namespace had a class called Common.  If you tried to type Common.GetUsersOnline(), .NET would say,… hey!  Accounting.Common exists, but there is no GetUsersOnline() in there.. So.. crash

So in order to help .NET solve this mystery, append global:: to the beginning of the namespace, and all will be fine.

global::Common.GetUsersOnline();


Other Interesting Posts

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Theme Design by TheBuckmaker