我有一个基本类型,它在系统的问题库中存储有关问题的信息,该系统生成练习问题集,帮助人们学习多项选择测试。其中存储的唯一信息是答案、提示和问题编号。当我创建一个实践测试时,我需要用一些属性来增加类型以存储提交的答案(测试可以分为多个部分),因此我创建了以下类:
public class MultipleChoiceQuestion
{
public Int32 Number { get; internal set; }
public String Prompt { get; internal set; }
public MultipleChoiceAnswer[] Choices { get; internal set; }
// constructors, etc...
}
public class PracticeTestQuestion : MultipleChoiceQuestion
{
public MultipleChoiceAnswer AnswerSelected { get; set; }
// is this right?
public PracticeTestQuestion(MultipleChoiceQuestion question)
{
...
}
}
最初,我把multipleechoiceQuestion作为practicatestQuestion的一个成员,但它在我的属性访问器中添加了很多额外的点,因此我将其更改为继承上面列出的类。目前,我正在为构造函数中的行分配所有的属性行,但这有点麻烦,我想知道是否有更好的方法。
C编译器不喜欢升迁类型是有充分理由的,所以我的问题是,从它们的多回音问题基类型实例化我的练习测试问题的最佳方法是什么?