0
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# 程序员一样制作对象。但是,看起来我的编译器找不到实体定义。

4

1 回答 1

1

默认情况下,类不是公共的,因此Inventory比返回它的实例的属性更难访问。

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

(无论是更改代码片段都会为我编译)

于 2012-04-22T19:54:30.827 回答