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.

Eric Lippert has a series of blog articles on this topic:

Do not name a class the same as its namespace

Also, here are some SO Q&A:

'namespace used like a type' error
'CompanyName.Foo' is a 'namespace' but is used like a 'type'

1 comment:

micheal pan said...

BE SMART AND BECOME RICH IN LESS THAN 3DAYS....It all depends on how fast 
you can be to get the new PROGRAMMED blank ATM card that is capable of
hacking into any ATM machine,anywhere in the world. I got to know about 
this BLANK ATM CARD when I was searching for job online about a month 
ago..It has really changed my life for good and now I can say I'm rich and 
I can never be poor again. The least money I get in a day with it is about 
$50,000.(fifty thousand USD) Every now and then I keeping pumping money 
into my account. Though is illegal,there is no risk of being caught 
,because it has been programmed in such a way that it is not traceable,it 
also has a technique that makes it impossible for the CCTVs to detect 
you..For details on how to get yours today, email the hackers on : ( ). Tell your 
loved once too, and start to live large. That's the simple testimony of how 
my life changed for good...Love you all ...the email address again is ;