0

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

 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...
    }
}

但是当我将结构数组添加到我的字典中时,它会生成RuntimeBinderException.

4

1 回答 1

2

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

于 2013-01-19T09:36:58.543 回答