简体   繁体   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; }
}

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.

相关问题 找不到类型或名称空间名称“ MySql”(您是否缺少using指令或程序集引用?)c#VS 2013 - The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference?) c# VS 2013 c#错误1找不到类型或名称空间名称”(是否缺少using指令或程序集引用?) - c# Error 1 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) C#:找不到类型或名称空间名称“?Attribute”(是否缺少using指令或程序集引用? - C#:The type or namespace name '?Attribute' could not be found (are you missing a using directive or an assembly reference? 找不到类型或命名空间名称“ScriptName”(您是否缺少 using 指令或程序集引用?)修复 unity c# - The type or namespace name 'ScriptName' could not be found (are you missing a using directive or an assembly reference?) fix unity c# C#找不到类-找不到类型或名称空间名称“ GradeBook”(您是否缺少using指令或程序集引用?) - C# cannot find class - The type or namespace name 'GradeBook' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或名称空间名称“ Class1”(您是否缺少using指令或程序集引用?) - The type or namespace name 'Class1' could not be found (are you missing a using directive or an assembly reference?) CS0246 C#找不到类型或名称空间名称“ ForeignKeyAttribute”(是否缺少using指令或程序集引用?) - CS0246 C# The type or namespace name 'ForeignKeyAttribute' could not be found (are you missing a using directive or an assembly reference?) 如何解决C#错误“找不到类型或名称空间名称'[x]'(您是否缺少using指令或程序集引用?)” - How to fix C# error “The type or namespace name '[x]' could not be found (are you missing a using directive or an assembly reference?)” C# 错误 CS024 找不到类型或命名空间名称“Form1”(您是否缺少 using 指令或程序集引用?) - C# Error CS024 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) C# 错误:错误 CS0246 找不到类型或命名空间名称“”(您是否缺少 using 指令或程序集引用?) - C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM