#39;namespace#39; but is used like a #39;type#39;(“命名空间,但用作“类型)
问题描述
这是我的程序,该类使用它称为 Time2我已将参考添加到 TimeTest我不断收到错误'Time2' is a 'namespace' but is used like a 'type'
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.
现在您显然对 Time2 有同样的问题.我怀疑如果你添加:
Now you apparently have the same problem with Time2. I suspect if you add:
using Time2;
到您的 using 指令列表中,您的代码将被编译.但是请,请,请解决更大的问题:有问题的名称选择.(点击上面的链接可以了解为什么这是一个坏主意的更多细节.)
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.)
(此外,除非您真的对编写基于时间的类型感兴趣,否则我建议您不要这样做……我说的是,作为一个这样做的人确实这样做了.使用内置功能或第三方库,例如,mine.正确处理日期和时间令人惊讶毛茸茸的.:)
(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. :)
这篇关于“命名空间",但用作“类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“命名空间",但用作“类型"
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
