473,320 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

"global::" usage

I find in other team member's project, they are referencing a type in
following format
"
public static global::ErrorReport.Description Description
= new global::ErrorReport.Description();
"

I do not understand the usage of "global" here, could anyone please
clarify its usage and what benift of using that. Thanks in advance.

Oct 22 '07 #1
7 1810
In C#, you can have namespaces and classes which share a name as well as
have nested namespaces/classes which have are shared, causing ambiguity.

Using "global::" indicates that the namespace after it will be processed
from the root level, not using the immediate namespace/class scope for
resolution.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<tw******@gmail.comwrote in message
news:11*********************@z24g2000prh.googlegro ups.com...
>I find in other team member's project, they are referencing a type in
following format
"
public static global::ErrorReport.Description Description
= new global::ErrorReport.Description();
"

I do not understand the usage of "global" here, could anyone please
clarify its usage and what benift of using that. Thanks in advance.

Oct 22 '07 #2
See http://msdn2.microsoft.com/en-us/lib...3d(VS.80).aspx. You
will often see the global:: qualifier in generated code to ensure that
it is refering to the correct types. I don't think I've ever since it
used manually - it's rarely necessary. It's unclear from your example
whether it is actually needed or not. It depends whether there are
more than one ErrorReport types.

Regards,
Kent

On Oct 22, 4:36 pm, twang...@gmail.com wrote:
I find in other team member's project, they are referencing a type in
following format
"
public static global::ErrorReport.Description Description
= new global::ErrorReport.Description();
"

I do not understand the usage of "global" here, could anyone please
clarify its usage and what benift of using that. Thanks in advance.

Oct 22 '07 #3

"Jon Skeet [C# MVP]" wrote:
Is there a difference between
that and the kind of class you can create in C++ or VB.NET?
The VB language supports classes at the global scope; but the VB.NET IDE
does not; you must specific a default namespace for a project in which all
classes and namespaces will be nested. I don't know what the global scope
resolution operator/keyword is in VB...

In C++/CLI you can also have managed classes at global scope. In C++ the
global scope resolution operator is '::', the equivalent of 'global::'. But,
often Intellisense gets confused with that...
Oct 22 '07 #4
>The VB language supports classes at the global scope; but the VB.NET IDE
>does not; you must specific a default namespace for a project in which all
classes and namespaces will be nested.
You don't have to specify one, you can leave it blank.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 22 '07 #5
I've had it complain that the root namespace can't be empty. But, with some
projects it does let you have an empty namespace. Interesting...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Mattias Sjögren" wrote:
The VB language supports classes at the global scope; but the VB.NET IDE
does not; you must specific a default namespace for a project in which all
classes and namespaces will be nested.

You don't have to specify one, you can leave it blank.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 22 '07 #6
It appears you can't have an empty root namespace for class library projects
in VB, but you can for Console/Winform applications. Interesting...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Mattias Sjögren" wrote:
The VB language supports classes at the global scope; but the VB.NET IDE
does not; you must specific a default namespace for a project in which all
classes and namespaces will be nested.

You don't have to specify one, you can leave it blank.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 22 '07 #7
I'm not sure what's different, but I have some VB class library projects not
allow a blank root namespace and some do. Interesting...

I'll add that to my list of reasons why I don't like VB...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"Mattias Sjögren" wrote:
The VB language supports classes at the global scope; but the VB.NET IDE
does not; you must specific a default namespace for a project in which all
classes and namespaces will be nested.

You don't have to specify one, you can leave it blank.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 22 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: mrbog | last post by:
I have an array/hash that stores path information for my app. As in, what directory this is in, what directory that's in, what the name of the site is, what the products are called, etc. It's...
1
by: Chris Stromberger | last post by:
This doesn't seem like it should behave as it does without using "global d" in mod(). d = {} def mod(): d = 3 mod() print d
7
by: Lyn | last post by:
Hi and Season's Greetings to all. I have a question regarding the use of a qualifier word "Global". I cannot find any reference to this in Access help, nor in books or on the Internet. "Global"...
9
by: Javaman59 | last post by:
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...
2
by: Steve | last post by:
I am new to this newsgroup & to .NET in general. I have been playing around with Visual Studio .NET, building and rendering web pages using VB "code behind" files. My problem / question is; How...
3
by: Pierre | last post by:
Hello, In an aspx page (mypage.aspx) from a web projet, I would like to get the value of a variable of the projet that is declared as public in a module. The variable can be called from...
4
by: =?Utf-8?B?QWxleCBNdW5r?= | last post by:
My Web application is developed in C# Visual Studio 2005 Professional. After deploying the application to the production server I am getting the following error: <%@ Application...
8
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
I have a public class called Database.cs. It has public static functions and I call them from ProjectA. The code looks something like: int intConnectionSuccessful = Database.ConnectToDatabase();...
4
ChrisWang
by: ChrisWang | last post by:
Hi, I am having trouble understanding the use of 'global' variables I want to use a global variable with the same name as a parameter of a function. But I don't know how to use them at the same...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.