簡體   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