Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any limit on number of classes that a namespace can have in .net?

Is there any limit on number of classes that a namespace can have in .NET? Further what is the recommended number of classes that there should be in a namespace?

like image 275
HotTester Avatar asked Aug 09 '10 19:08

HotTester


People also ask

How many classes can be created in a namespace?

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.

Can you use multiple namespaces C#?

In c#, we can define and access multiple namespaces in our application with using keyword. To access the custom namespace classes, we need to import the custom namespace with using keyword and need to create an instance for that classes in our application.


2 Answers

There's no specified maximum number of classes "per namespace"-- a namespace is really just a part of the Type's full name, not a logical entity in the CLR

The recommended number is whatever makes sense: use namespaces to group logically related classes together.

I'm sure that if you have enough types you can run the compiler or the runtime out of memory, but that's a physical limit not a specification - and it probably doesn't matter if they are in the same namespace or not.

Note that as Steven points out, you can also have the same namespace present in multiple assemblies as well.

like image 162
Philip Rieck Avatar answered Sep 21 '22 18:09

Philip Rieck


I tried it out: I just built an assembly containing 1,000,000 types without any problem. However at 5,000,000 the C# compiler ran out of memory :-).

like image 34
Steven Avatar answered Sep 19 '22 18:09

Steven