这可能是一个愚蠢的问题,但我是C#的新手。我想知道是否有一种方法直接在子类中使用父级的属性。我做了很多埃菲尔,当一个类被一个或多个类继承时(因为是埃菲尔没有接口,你可以继承多个类)。访问父母属性
就这样为例:(艾菲尔langage)
父类:
class Parent
features
int id
string lastName
子类:
class Child inherit
PARENT
feature
bool isChild
在这种情况下,儿童类已经有访问ID和lastName并且可以直接设置为Child属性的一部分,不必创建Parent。
但到目前为止,我做了这个(C#langage):
父类:
public class Character
{
Int32 Id;
String name;
List<String> images;
public Character()
{
name = "";
images = null;
}
public Character(string a_name, List<String> imagePaths)
{
name = a_name;
images = imagePaths;
}
public Character(Int32 a_id, string a_name, List<String> imagePaths)
{
Id = a_id;
name = a_name;
images = imagePaths;
}
}
子类:
public class NPC : Character
{
public bool isVender;
public NPC()
{
Character character = new Character();
isVender = false;
}
public NPC(string a_name, List<String> images)
{
Character caracter = new Character(a_name, images);
isVender = false;
}
public NPC(string a_name, List<string> images, bool a_bool)
{
Character caracter = new Character(a_name, images);
isVender = a_bool;
}
}
所以有我的问题,是有办法像Eiffel一样直接在C#中获得父对象的属性?
不错谢谢你! –