Reputation: 7546
I need to contain a set of static string properties under a namespace such as:
namespace1 N1 {
namespace N2 {
public const string A = "a";
}
public const string B = "c";
namespace N3 {
public const string A = "a";
}
}
Is it possible to have nested namespaces in C#? What is the better design approach? Using static classes or using namespaces in this case?
thanks
Upvotes: 2
Views: 254
Reputation: 67065
Yes, creating a nested namespace is possible. However, I believe the preferred methodology for something like this would be to create a resource file
This gives you the added benefit of being able to change without a code change, as well as to support multiple languages.
Upvotes: 1
Reputation: 80714
Yes, it is possible to have nested namespaces in C#.
However, it is impossible to have a constant directly inside a namespace. You have to put it into a class.
Upvotes: 7