Keith,
Consider this example:
// The following line imports namespace B types (Bar1 & Bar2).
using B;
namespace A.C.D
{
// The following line imports namespace A.B types (Foo1 & Foo2).
using B;
}
namespace A.B
{
public class Foo1 { }
public class Foo2 { }
}
namespace B
{
public class Bar1 { }
public class Bar2 { }
}
As you can see changing the location of the using statement changes
what it is imported. I believe the formal explanation is in section
10.7 of the C# specification (ECMA version).
"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."
That is quite possibly the most confusing sentence I've ever read!
Brian
Keith Patrick wrote:
Can someone tell me the difference in terms of actual implications using:
namespace MyNamespace {
using System;
class MyClass {...}
}
vs.
using System;
namespace MyNamespace {
class MyClass {...}
}
are? There's a framework recommendation that the former be used (and some
ASP.Net templates create classes like this), but I use the latter. I've
tried both but could never determine a difference between the two, so I'm
unsure why there's a recommendation to do one over the other.