In C#, the namespace keyword is followed by the main code block and it is considered as a visible starter for the code.
It is simply a logical collection of classes and there is no physical mapping.
Unlike Java, there is no relationship between the namespace and class names, directory, file structure.
Organizationally, it often makes sense to gather all the files associated with a single namespace into a single directory and to have a one-to-one relationship between class names and files, but this is strictly a matter of preference.
- namespace Project
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Logic
- }
- }
- }
Interestingly, you can create nested namespaces in our C#.
- namespace Project
- {
- namespace Team {
-
- namespace Module {
- //class and other type declarations go here
- }
- }
- }
Also, you can navigate between the namespaces like this.
- namespace Project.Team.Module
- {
- //Logic
- }
..