[英]C#: The type or namespace name 'class' could not be found(are you missing a using directive for an assembly reference?)
class World
{
bool _playerHasWonGame = false;
public void Update()
{
Entity player = FindEntity("Player"); //ERROR: The type or namespace name 'Entity' could not be found(are you missing a using directive for an assembly reference?)
}
private Entity FindEntity(string p) //Same ERROR
{
throw new NotImplementedException();
}
}
class Inventory
{
public bool Contains(Entity entity)
{
return false;
}
}
public class Entity
{
public Inventory Inventory { get; set; }
}
The error part is Entity. 错误部分是实体。
I create Entity class, and try to make Entity object in World class. 我创建了Entity类,并尝试在World类中创建Entity对象。
As I understood, it should work. 据我了解,它应该起作用。 I just tried to make object like other C# programmer does. 我只是想像其他C#程序员一样制作对象。 But, looks like my compiler cannot find Entity definition. 但是,看来我的编译器找不到实体定义。
Classes are not public by default, so Inventory
is less accessible than the property which is returning an instance of it. 默认情况下,类不是公共的,因此与返回其实例的属性相比, Inventory
的访问性较低。
Either change Entity
to be internal (so it and its properties will exist in the same scope as Inventory
) or make Inventory
public. 可以将Entity
更改为内部Entity
(这样它及其属性将与Inventory
处于同一范围内)或将Inventory
公开。
(With either change the snippet compiles for me) (通过更改任一代码段即可为我编译)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.