(пример изменен с животного на вопрос)
Код: Выделить всё
class Survey
{
Question[] questions
}
Код: Выделить всё
class Question
{
string question
bool required
}
Код: Выделить всё
class ChoiceQuestion: Question
{
AnswerOptions[] answerOptions
bool isMultiple
}
Код: Выделить всё
class FreeTextQuestion: Question
{
}
Код: Выделить всё
Survey survey = new Survey()
Question[] questions = [new FreeTextQuestion(), new ChoiceQuestion())]
survey.questions = questions
Код: Выделить всё
foreach(Question question in questions)
{
if(question is FreeTextQuestion)
{
FreeTextQuestion freeTextQuestion = question as FreeTextQuestion
}
else if (a is ChoiceQuestion)
{
ChoiceQuestion choiceQuestion = question as ChoiceQuestion
}
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... lass-array