Pages

Sunday, 13 December 2015

DO NOT use the same name for class and its namespace

In the following code namespace Foo contains class with the same name - Foo:

This causes compiler to issue an error:

Error CS0118: 'Foo' is a namespace but is used like a type

The problem is in that compiler does not know if we are trying to use new on the namespace or on the actual class. To rectify this, we have to use the fully qualified class name (which includes namespace):

In some cases this might not be enough so it is better to avoid using same name for class and for its namespace.