【问题标题】:Hierarchical dictionary分层字典
【发布时间】:2014-04-12 21:42:54
【问题描述】:

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

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

RadioButton我保留了一个答案文本。

【问题讨论】:

  • 我认为你不应该在这里使用字典。
  • List&lt;Question&gt; 怎么样?

标签: c# winforms dictionary


【解决方案1】:

您为什么不为您的问题创建一个类并将您的逻辑封装在其中并存储有关您的问题的所有必要信息?

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&lt;int, Question&gt;

【讨论】:

    猜你喜欢
    • 2015-05-08
    • 2014-10-12
    • 2012-04-28
    • 2020-07-06
    • 1970-01-01
    • 2020-09-01
    • 2018-06-24
    • 1970-01-01
    • 2023-03-25
    相关资源
    最近更新 更多