473,608 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"global::" usage

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

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 1824
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.co m

<tw******@gmail .comwrote in message
news:11******** *************@z 24g2000prh.goog legroups.com...
>I find in other team member's project, they are referencing a type in
following format
"
public static global::ErrorRe port.Descriptio n Description
= new global::ErrorRe port.Descriptio n();
"

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::ErrorRe port.Descriptio n Description
= new global::ErrorRe port.Descriptio n();
"

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
2693
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 called $glb. So, every function so far looks like this: function something() { global $glb; }
1
1825
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
2680
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" seems to be recognised by Access in at least three cases:- 1) "Global Const". Recently someone in this group helped me resolve a problem, and it involved the use of a Global Const. By Googling "Global Const", I got plenty of hits -- but they...
9
2481
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 is, do "global" and "::" always go together? Is there any other use for these operators, than as a pair? TIA,
2
3698
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 do I ensure that changes made to the "Global.asax.vb" file are immediately reflected in the "Global.asax" file? After I change to the "Global.asax.vb" file, the "Global.asax" file date modified does not change and I do not see the updated values...
3
3931
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 anywhere in the code behind page and in the class files, but when I try to call it from an aspx page, it raises an error. <%=myvar%> in mypage.aspx raise an error : the name "myvar" is not declared.
4
5921
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 Codebehind="Global.asax.cs" Inherits="WebApplication.Global" Language="C#" %> I found numerous references to this problem on the web and tried what seems like a few (tens) suggestions, at least the ones I was able to understand. But alas no luck. Pleeeeeeeease...
8
1277
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(); Works great. Now, I have another project, ProjectB on a different server. I copy and add Database.cs to the project and also call the functions the exact same way as above. However, I always get this error message: 'The name 'Database'...
4
3405
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 time. Here is a snippet of example code: def foo (a): global p global a p = a + 3 #here "a" will be reference to the global one a = 1
0
8003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8498
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8152
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.