【发布时间】:2015-03-04 15:19:53
【问题描述】:
有没有人遇到过如下一些较旧的 C# 代码,为了克服后来的编译器错误“'car' is a 'namespace' but is used like a 'type'”,等效的方法是什么。
非常感谢。
namespace something.car
{
public class Display : UserControl
{
private car _car; // comppiler error here
public car carConfig // comppiler error here
{
get
{
return this._car;
}
set
{
this._car = value;
}
}
}
}
【问题讨论】:
-
car在您的示例中是一个命名空间。 -
不要将类命名为命名空间。就这么简单。您可能可以为命名空间设置别名以避免该问题。
-
在这个例子中,汽车是一个类吗?按原样阅读您的示例,您正在尝试实例化一个命名空间,编译器正确指出这是无法完成的。
标签: c# namespaces