views:

266

answers:

3

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.

+4  A: 

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.

Steve Rowe
+2  A: 

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.

Neil N
+2  A: 

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.

Peter Morris