I have created array of struct elements and have to add it into my dictionary.My code is given below:
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...
}
}
But when i adding the array of struct into my dictionary it generates RuntimeBinderException.
If it’s a RuntimeBinderException at this line, your current dynamic student may not have any studentId property, or the property may not be visible