Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'namespace' but is used like a 'type'

My program uses a class called Time2. I have the reference added to TimeTest but I keep getting the error, 'Time2' is a 'namespace' but is used like a 'type'.

Could someone please tell me what this error is and how to fix it?

namespace TimeTest {   class TimeTest   {     static void Main(string[] args)     {         Time2 t1 = new Time2();     }   } } 
like image 442
TheAce Avatar asked Feb 21 '13 16:02

TheAce


1 Answers

I suspect you've got the same problem at least twice.

Here:

namespace TimeTest {     class TimeTest     { } 

... you're declaring a type with the same name as the namespace it's in. Don't do that.

Now you apparently have the same problem with Time2. I suspect if you add:

using Time2; 

to your list of using directives, your code will compile. But please, please, please fix the bigger problem: the problematic choice of names. (Follow the link above to find out more details of why it's a bad idea.)

(Additionally, unless you're really interested in writing time-based types, I'd advise you not to do so... and I say that as someone who does do exactly that. Use the built-in capabilities, or a third party library such as, um, mine. Working with dates and times correctly is surprisingly hairy. :)

like image 180
Jon Skeet Avatar answered Sep 20 '22 10:09

Jon Skeet