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

本文关键字:程序集 是否 引用 指令 using 类型 找不到 命名空间 class | 更新日期: 2023-09-27 18:32:05

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; }
}

错误部分是实体。

我创建了实体类,并尝试在世界类中制作实体对象。

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

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

默认情况下,

类不是公共的,因此Inventory比返回其实例的属性更难访问。

要么将Entity更改为内部的(因此它及其属性将存在于与Inventory相同的范围内),要么Inventory公开。

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