I saw in a recent post the :: operator used to reach the global namespace, as
in
global::MyNames pace
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,
Javaman 9 2491
Javaman,
AFAIK, there's no "global" keyword in c# 2.0. You only use the operator '::'
to indicate the compiler to start the search from the 'outest' scope:
namespace A {
namespace System {
class X {
public void Message(string s)
{
::System.Window s.Forms.Message Box.Show(s); // '::' needed here
}
}
}
}
Regards - Octavio
"Javaman59" <Ja*******@disc ussions.microso ft.com> escribió en el mensaje
news:76******** *************** ***********@mic rosoft.com... I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNames pace
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,
Javaman
You should probably check before you post. Your code will not compile - thats a C++ construct. There is a global keyword in C# v2 and it always goes together with :: to indicate global scope of the type.
global::System. Windows.Forms.M essageBox.Show( "foo");
Regards
Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
Javaman,
AFAIK, there's no "global" keyword in c# 2.0. You only use the operator '::'
to indicate the compiler to start the search from the 'outest' scope:
namespace A {
namespace System {
class X {
public void Message(string s)
{
::System.Window s.Forms.Message Box.Show(s); // '::' needed here
}
}
}
}
Regards - Octavio
"Javaman59" <Ja*******@disc ussions.microso ft.com> escribi? en el mensaje
news:76******** *************** ***********@mic rosoft.com... I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNames pace
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,
Javaman
[microsoft.publi c.dotnet.langua ges.csharp]
Richard,
Thanks for your correction.
Actually I did that check, referring to a MSDN Magazine I always considered
excellent: http://msdn.microsoft.com/msdnmag/is...0/default.aspx
Maybe the article is little bit old and specs have changed since then?
Regards - Octavio
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> escribió en
el mensaje news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. You should probably check before you post. Your code will not compile - thats a C++ construct. There is a global keyword in C# v2 and it always goes together with :: to indicate global scope of the type.
global::System. Windows.Forms.M essageBox.Show( "foo");
Regards
Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
Javaman,
AFAIK, there's no "global" keyword in c# 2.0. You only use the operator '::' to indicate the compiler to start the search from the 'outest' scope:
namespace A { namespace System { class X { public void Message(string s) { ::System.Window s.Forms.Message Box.Show(s); // '::' needed here } } } }
Regards - Octavio
"Javaman59" <Ja*******@disc ussions.microso ft.com> escribi? en el mensaje news:76******** *************** ***********@mic rosoft.com...I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNames pace
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,
Javaman [microsoft.publi c.dotnet.langua ges.csharp]
Javaman59 wrote: I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNames pace
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
Thanks Octavio for answering my question. I had a quick look at the article
too, and it does say the "::" is valid as a prefix (ie. your code should
compile). Maybe someone was hoping that c++ style "::" would return, but
Microsoft eventually decided against it :). I'm glad, too, because I always
found that dangling "::" confusing - "global::" is much cleareer!
- Javaman
"Octavio Hernandez" wrote: Richard,
Thanks for your correction. Actually I did that check, referring to a MSDN Magazine I always considered excellent:
http://msdn.microsoft.com/msdnmag/is...0/default.aspx
Maybe the article is little bit old and specs have changed since then?
Regards - Octavio
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> escribió en el mensaje news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. You should probably check before you post. Your code will not compile - thats a C++ construct. There is a global keyword in C# v2 and it always goes together with :: to indicate global scope of the type.
global::System. Windows.Forms.M essageBox.Show( "foo");
Regards
Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
Javaman,
AFAIK, there's no "global" keyword in c# 2.0. You only use the operator '::' to indicate the compiler to start the search from the 'outest' scope:
namespace A { namespace System { class X { public void Message(string s) { ::System.Window s.Forms.Message Box.Show(s); // '::' needed here } } } }
Regards - Octavio
"Javaman59" <Ja*******@disc ussions.microso ft.com> escribi? en el mensaje news:76******** *************** ***********@mic rosoft.com...I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNames pace
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,
Javaman [microsoft.publi c.dotnet.langua ges.csharp]
Thanks Oliver,
That's really what I was looking for. MSDN on the "::" operator says that it
is placed between two identifiers, but it isn't clear how it can be used,
apart from "global::SomeNa mespace". Your reply clears it up for me.
- Javaman
"Oliver Sturm" wrote: Javaman59 wrote:
I saw in a recent post the :: operator used to reach the global namespace, as in
global::MyNames pace
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
One final (minor) point.... MSDN on the "::" operator says that it is placed between two identifiers
Note that is says "identifier " and not "keyword".
Technically, global is not a keyword (neither are get, set, value, partial,
alias, add, remove, where, yield).
Javaman,
Researching on this topic I've found that there is already an official
standard for C# 2.0: http://www.ecma-international.org/pu...s/Ecma-334.htm
Of course it fully describes the usage of the '::' operator and the 'global'
identifier.
Thanks and best regards - Octavio
"Javaman59" <Ja*******@disc ussions.microso ft.com> escribió en el mensaje
news:0B******** *************** ***********@mic rosoft.com... Thanks Octavio for answering my question. I had a quick look at the article too, and it does say the "::" is valid as a prefix (ie. your code should compile). Maybe someone was hoping that c++ style "::" would return, but Microsoft eventually decided against it :). I'm glad, too, because I always found that dangling "::" confusing - "global::" is much cleareer!
- Javaman
"Octavio Hernandez" wrote:
Richard,
Thanks for your correction. Actually I did that check, referring to a MSDN Magazine I always considered excellent:
http://msdn.microsoft.com/msdnmag/is...0/default.aspx
Maybe the article is little bit old and specs have changed since then?
Regards - Octavio
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> escribió en el mensaje news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. > You should probably check before you post. Your code will not compile - > thats a C++ construct. There is a global keyword in C# v2 and it always > goes together with :: to indicate global scope of the type. > > global::System. Windows.Forms.M essageBox.Show( "foo"); > > Regards > > Richard Blewett - DevelopMentor > http://www.dotnetconsult.co.uk/weblog > http://www.dotnetconsult.co.uk > > Javaman, > > AFAIK, there's no "global" keyword in c# 2.0. You only use the operator > '::' > to indicate the compiler to start the search from the 'outest' scope: > > namespace A { > namespace System { > class X { > public void Message(string s) > { > ::System.Window s.Forms.Message Box.Show(s); // '::' needed here > } > } > } > } > > Regards - Octavio > > > "Javaman59" <Ja*******@disc ussions.microso ft.com> escribi? en el > mensaje > news:76******** *************** ***********@mic rosoft.com... > >I saw in a recent post the :: operator used to reach the global > >namespace, > >as > > in > > > > global::MyNames pace > > > > 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, > > > > Javaman > > > > [microsoft.publi c.dotnet.langua ges.csharp]
Thanks Mark. That is actually very helpful, and worth remembering. Now I know
why I couldn't find "global keyword" in the help index.
- Javaman
"MarkT [developmentor]" wrote: One final (minor) point....
MSDN on the "::" operator says that it is placed between two identifiers
Note that is says "identifier " and not "keyword".
Technically, global is not a keyword (neither are get, set, value, partial, alias, add, remove, where, yield). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
}
|
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
|
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...
|
by: j |
last post by:
Anyone here feel that "global variables" is misleading for variables
whose scope is file scope? "global" seems to imply global visibility,
while this isn't true for variables whose scope is file scope. If you
have a variable whose scope is file scope in another translation unit,
you have to provide a local declaration to access that variable from
the other translation unit.
Also, I don't see "global variable" used once in the standard....
|
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...
| |
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.
|
by: twang090 |
last post by:
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.
|
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...
|
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
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |