首先让我为提出这么多愚蠢的问题而道歉。我刚刚开始使用c#并试图了解类/接口和继承。在这个例子中,我有三个共享接口的类。像这样;
public class Platform : IGraphic
{
public GraphicType Type;
public string Name;
public Texture2D Icon;
public string GetName()
{
return Name;
}
public Texture2D GetIcon(GraphicType a_type)
{
if (a_type == Type || a_type == GraphicType.CHARACTERS)
return Icon;
else
return null;
}
}
public class Decal : IGraphic
{
public GraphicType Type;
public string Name;
public Texture2D Icon;
public string GetName()
{
return Name;
}
public Texture2D GetIcon(GraphicType a_type)
{
if (a_type == Type)
return Icon;
else
return null;
}
}
public class Character : IGraphic
{
public GraphicType Type;
public string Name;
public Texture2D Icon;
public string GetName()
{
return Name;
}
public Texture2D GetIcon(GraphicType a_type)
{
if (a_type == Type || a_type == GraphicType.CHARACTERS)
return Icon;
else
return null;
}
}
public interface IGraphic
{
string GetName();
Texture2D GetIcon(GraphicType a_type);
}
当我调用GetName()时,它工作正常,但当我尝试调用GetIcon()时,我收到一条错误消息; 错误1无法隐式转换类型' bool'到' Microsoft.Xna.Framework.Graphics.Texture2D' 我在这做错了什么?