1

I read C# spec and googled for it, but found nothing.

I am 99% sure there is no such feature like unit namespace directive in C#, but the question is: why? Are there idiomatic or technical reasons?

It is convenient, especially when most of our file consist of single namespace. Is there any feature requests or proposals out there? Maybe we can make one?

// with unit namespace
namespace Foo;
class Bar { ... } // Class Bar declared inside Foo Namespace
struct Baz { ... } // Baz is inside Foo too

// without
namespace Foo {
  class Bar { ... }
  class Baz { ... }
}

Or maybe there is a way to re-export global symbols? I mean first you declare everything inside global namespace, and then publish public symbols in selected namespace?

The deep nesting of C# code is one of the most annoying thing for me.

I really enjoyed C++ ability to forward declare even nested classes and then define them without even 1 extra level of nesting.

Thanks for your time.

2
  • You should never use the global namespace. Commented Aug 15, 2016 at 21:18
  • It is not very pleasant to see you should never. At least I wonder why global namespace was added to the language. There could be interesting reasons that are not so obvious, at least for me. I want to know those reasons and you can provide this information, if you have an answer, of course. Commented Aug 15, 2016 at 21:27

1 Answer 1

1

Logically, namespaces are block, just like classes, except that they can only contain types, not members.

Having a special syntax for this kind of block would be pointless and confusing.

Sign up to request clarification or add additional context in comments.

2 Comments

I see its useful for me, so it is not pointless at least for me. Also, I do think unit namespace is something easy to understand. It would look like Go package declaration or like PHP namespace directive. If I remember correctly, perl6 has this too. The point is: there are persons who think it is useful.
You could file a feature request on GitHub. However, it is very likely to be declined as not worth doing. It'd be interesting to see if they give other reasons, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.