2014-04-12 181 views
-3

我需要在字典中保留问题和答案。关键是一些问题。我认为一个值应该是分层的,因为我需要保留一个问题文本,一张图片和一个带有4个答案的字典(一个关键是答案的文本,值是布尔 - 无论答案是真还是假)。 我设法只写这个,但它没有保留一个问题和图片的文本。分层字典

Dictionary<int, Dictionary<RadioButton, bool>> questions = new Dictionary<int, Dictionary<RadioButton, bool>>(); 

RadioButton我保留一个答案。

+1

我不认为你应该使用字典在这里。 –

+0

'List '''怎么样? –

回答

3

为什么不为你的问题创建一个类,并将你的逻辑封装在它里面,并存储你的问题的所有必要信息?

class Question 
{ 
    public int Id { get; set; } 
    public string Text { get; set; } 
    public string Answer1 { get; set; } 
    public string Answer2 { get; set; } 
    public string Answer3 { get; set; } 
    public string Answer4 { get; set; } 
    public string CorrectAnswer { get; set; } 

    public Image Image { get; set; } 

    // add more properties if necessary 
} 

然后有一个Dictionary<int, Question>