Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a maximum number of namespace levels allowed in C#?

Question out of curiosity. I have successfully created a 300 levels deep namespace nesting. Visua studio happily suggest "a.a.a.a.a[...].a.theclass as a quick fix if i enter the class name buried below those layers of namespacing.

Does anyone know if there is an actual limit as for how deeply nested namespaces can be?

No case where I'd need it, just curious.

like image 928
Culme Avatar asked Oct 09 '15 19:10

Culme


People also ask

Can a namespace hold more than one class?

Two classes with the same name can be created inside 2 different namespaces in a single program. Inside a namespace, no two classes can have the same name.

How many namespaces are there in C#?

There four types of namespaces in C#.

Can namespace be nested?

In C++, namespaces can be nested, and resolution of namespace variables is hierarchical. For example, in the following code, namespace inner is created inside namespace outer, which is inside the global namespace.


1 Answers

From documentation - Namespace Statement

You can declare one namespace within another. There is no strict limit to the levels of nesting you can declare, but remember that when other code accesses the elements declared in the innermost namespace, it must use a qualification string that contains all the namespace names in the nesting hierarchy.

like image 77
Habib Avatar answered Nov 15 '22 09:11

Habib