In C++, if you write using namespace
in a header, then it will be in effect for anyone who includes that header. This makes it pretty much unusable in headers. At that point, you might as well avoid it (at global scope) in .cpp files as well, if only for the sake of consistency, and to make moving implementations between .h and .cpp easier.
(note that locally scoped using namespace
- i.e. within a function - are generally considered fine; it's just that they don't help with verbosity much)
In C#, there is nothing like #include
, and the scope of a using
directive will never span beyond a single .cs file. So it's pretty much safe to use everywhere.
The other reason is the design of the standard library. In C++, you just have std
(well, now also a few more underneath it, but they are rarely used). In C#, you have gems such as System.Collections.Generic
, which is extremely verbose for something that's used very commonly. It's just much more painful to avoid using
in C# than it is in C++.
To sum it up, while C# and C++ do share some common design, on the matter of code modularity (I'd assign headers, modules, namespaces all to that group), their design is very different.