Reputation:
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.
As I understood, it should work. I just tried to make object like other C# programmer does. But, looks like my compiler cannot find Entity definition.
Upvotes: 0
Views: 2001
Reputation: 2972
Classes are not public by default, so Inventory
is less accessible than the property which is returning an instance of it.
Either change Entity
to be internal (so it and its properties will exist in the same scope as Inventory
) or make Inventory
public.
(With either change the snippet compiles for me)
Upvotes: 1