繁体   English   中英

C#:找不到类型或名称空间名称“类”(是否缺少程序集引用的using指令?)

[英]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; }
}

错误部分是实体。

我创建了Entity类,并尝试在World类中创建Entity对象。

据我了解,它应该起作用。 我只是想像其他C#程序员一样制作对象。 但是,看来我的编译器找不到实体定义。

默认情况下,类不是公共的,因此与返回其实例的属性相比, Inventory的访问性较低。

可以将Entity更改为内部Entity (这样它及其属性将与Inventory处于同一范围内)或将Inventory公开。

(通过更改任一代码段即可为我编译)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM