Re: Placement of the using keyword

From: Brian Gideon (briangideon_at_yahoo.com)
Date: 03/14/05


Date: 14 Mar 2005 06:42:37 -0800

Sean,

Thanks for the feedback. I also noticed that the differences in
placement of the using keyword were limited to normal scoping rules.
Section 9.3.1 is basically what you've cited.

I suspect you may be right about rolling up the namespace hierarchy.
But you'd think that would be mentioned somewhere in the specification.
 If it isn't then we can only make assumptions based on observations.

Brian

Sean Hederman wrote:
> > 1) Section 9.3.2 of the specification does not mention the
> > differences in the placement of the using keyword. Why?
> > Is it described somewhere else in the specification?
>
> Just had a look at Helsbergs book, and it appears that the
> only difference in the placement relates to the scope of
> aliases:
>
> // File1.cs
> using R = N1.N2; // N1.N2 contains a class called OtherClass
>
> namespace A {
> class Class1 : R.OtherClass { // OK
> }
> }
> namespace B {
> class Class2 : R.OtherClass { // OK
> }
> }
>
> // File2.cs
> namespace A {
> using R = N1.N2;
> class Class1 : R.OtherClass { // OK
> }
> }
> namespace B {
> class Class2 : R.OtherClass { // Not OK
> }
> }
>
> > 2) How does the compiler know to import A.B types as
> > opposed to B types when "using B" is contained within
> > namespace A.C.D? Does the using keyword somehow
> > search the namespace hierarchy it is contained within
> > (in this case A.C.D) to find a match first and then
> > search outside as a last resort?
>
> Interesting, from what I can see in the documentation,
> using B in A.C.D should import B & A.C.D.B. If you're
> right (and I assume you are), it probably means that it
> rolls up the namespace hierarchy: importing B & A.B &
> A.C.B & A.C.D.B.
>



Relevant Pages

  • Re: Placement of the using keyword
    ... > placement of the using keyword were limited to normal scoping rules. ... > I suspect you may be right about rolling up the namespace hierarchy. ... > Sean Hederman wrote: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Placement of the using keyword
    ... "Brian Gideon" wrote in message ... Notice that when the using keyword is placed outside ... > inside the namespace decleration. ... > in the placement of the using keyword. ...
    (microsoft.public.dotnet.languages.csharp)
  • Placement of the using keyword
    ... I stumbled across something odd today about the placement of the using ... Notice that when the using keyword is placed outside ... inside the namespace decleration. ... keyword somehow search the namespace hierarchy it is contained within ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A query on C#
    ... > aa.aa obja = new aa.aa; ... > keyword for the namespace 'aa'. ... The simple name aa now refers to the class aa.aa and not to the namespace ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Matz says namespaces are too hard to implement - why?
    ... invoke that method from another method invoked in that namespace the ... via a keyword or other syntax, the overhead of checking for a namespace ... class StringDecorate ...
    (comp.lang.ruby)