我创建了struct元素数组,并且必须将它添加到我的字典中。我的代码如下:
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
。
答案 0 :(得分:2)
如果这是此行的RuntimeBinderException,您当前的动态学生可能没有任何studentId属性,或者该属性可能不可见