------------------
using System;
namespace SomeNamespace
{
}
-------------------
namespace SomeNamespace
{
using System;
}
Not quite, or at least not always.See
http://blogs.msdn.com/ericlippert/archive/2007/06/25/inside-or-outside.aspx
Jon
In that particular case, yes. But, like Jon said, it can make a
difference. I discovered this oddity and posted it in this group
quite some time ago hoping someone could point me to the section in
the specification that discusses it. I did some scouring of my own
and I believe the crucial section is 10.7 (ECMA) where it says:
"The scope of a namespace member declared by a namespace-member-
declaration within a namespace-declaration whose fully qualified name
is N, is the
namespace-body of every namespace-declaration whose fully qualified
name is N
or starts with N, followed by a period."
Clear as mud huh?
Don't you have a web page of C# oddities? This would almost certainly
qualify to be listed!
I've got this one:
http://pobox.com/~skeet/csharp/teasers.html
if that's what you mean. Yes, I could add it - along with a whole bunch
I suspect I've got queued up somewhere!
--
Jon Skeet - <sk...@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Yep, that's the link I was referring too.
Okay - I'll try to remember to do it soonish. (At the very least I'll
add an HTML comment to remind me :)
using B; // Try it here
namespace A.C
{
using B; // and then here next!
public class Program
{
public static void Main(string[] args)
{
Foo.DoSomething();
}
}
}
namespace A.B
{
public class Foo
{
public static void DoSomething()
{
Console.WriteLine("A.B.Foo.DoSomething()");
}
}
}
namespace B
{
public class Foo
{
public static void DoSomething()
{
Console.WriteLine("B.Foo.DoSomething()");
}
}
}
Ooh, that will certainly make my life easier. Thanks very much :)
so which one is better? or perferred?
"Brian Gideon" <brian...@yahoo.com> wrote in message
news:f4cde640-6059-489b...@l42g2000hsc.googlegroups.com...
"Tem" <tem...@yahoo.com> wrote in message
news:OqplAnZs...@TK2MSFTNGP03.phx.gbl...
I'm not sure it matters really. I guess there is a strong argument
for putting the using statement outside the namespace declaration
since that yields the most intuitive result.
I actually stumbled upon this on my own several years ago because I
was putting the using statement inside the namespace declaration and
actually had this strange situation (which I posted as an example in
this thread in a response to Jon) occur once. It was a very difficult
bug to find because, at that time, I felt like the behavior of the
using statement was so fundamentally established to me that I didn't
even entertain the possiblity that it was the root of my problem. I
was lead down the wrong path of thinking there was some obscure bug in
the compiler.