Should I be using a C# namespace for simple console apps?
-
21-08-2019 - |
Question
I'm new to C#, and am curious about best practice for using namespaces.
I have a solution that contains a single class library project, along with several, small console app projects. All the console app projects do is parse command-line arguments and call different classes within the library project. The library project uses the standard CompanyName.Tool convention.
My question is, since the only purpose of a given console app is to a class in the library project, and will never itself be called from another project or class, do I need to put it inside a namespace? It seems unnecessary.
Solution
You are correct. It is unnecessary. The only reason you would want to be using a namespace is if you are creating libraries for re-use in many programs.
OTHER TIPS
No, you dont need to. I find it's easier for maintainability to keep the entry points of an app (console, web, or windows) without namespaces.
The project will have a default namespace if you look in the properties. Any class not given an explicit namespace will inherit that one. So you don't need a namespace for any class unless it differs from the project one.