'命名空间',但用于像一个“类型” [英] 'namespace' but is used like a 'type'

查看:129
本文介绍了'命名空间',但用于像一个“类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的程序类使用它被称为时间2
我已经引用添加到TimeTest
我不断收到错误时间2是一个命名,但使用像一个类型

This is my program the class uses it is called Time2 I have the reference added to TimeTest 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();
    }
  }



}

}

推荐答案

我怀疑你已经得到了同样的问题的至少两次

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

这里:

namespace TimeTest
{
    class TimeTest
    {
}

...你声明具有相同的名称,因为它的命名空间中的一个类型。的不要那样做。

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

现在,你显然有时间2 同样的问题。我的犯罪嫌疑人的如果添加:

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. :)

这篇关于'命名空间',但用于像一个“类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆