如何添加数组结构到字典,

本文关键字:结构 字典 数组 何添加 添加 | 更新日期: 2023-09-27 17:54:19

我已经创建了一个结构元素数组,并且必须将它添加到我的字典中。我的代码如下:

 struct answerDetails
 {
    public string qId;
    public string question;
    public string answer;
    public string hint;
 }
private answerDetails[] answers;
private Dictionary<string, answerDetails[]> studList = new Dictionary<string, answerDetails[]>();   
foreach (var data in dynObj.Success)
{
    foreach (var student in data.Answers)
    {
        answers = new answerDetails[student.Ques_Ans.Count];
        int i = 0;
        foreach (var qInfo in student.Ques_Ans)
        {
            answers[i].qId = qInfo.qId;
            answers[i].question = qInfo.question;
            answers[i].answer = qInfo.answer;
            answers[i].hint = qInfo.hint;
            i++;                 
        }
        studList.Add(student.studentId,answers);//raising error...
    }
}

但是当我将struct数组添加到我的字典中时,它生成了RuntimeBinderException

如何添加数组结构到字典,

如果这一行是RuntimeBinderException,则当前的动态学生可能没有任何studentId属性,或者该属性可能不可见