I’m building a ASP.net quiz engine and I’m using a previous quiz engine i did in Flash as a template for the ASP version. I’m stuck on how I can achieve the following code in ASP.net
// array to hold the answers
var arrAnswers:Array = new Array();
// create and array of answers for the given question
arrAnswers[i] = new Array();
// loop through the answers of each question
for (j=0; j<dataXML.question[i].answers.length(); j++)
{
//array of answers for that given question is pulle from XML data
arrAnswers[i][j] = dataXML.question[i].answers[j].@choice.toString();
// if the given answer is the correct answer then set that value to the arrcorrect
}
Can anyone help on how I can get above action script code in ASP.net?
To convert this code directly, you would declare a jagged array, like this:
You would then initialize the elements of the outer array using LINQ to XML, like this:
You could also do it without a loop, like this:
However, it would be best to refactor the array into a
QuizQuestionclass with aReadOnlyCollection<String> AnswerChoices.For example:
Modify the LINQ to XML code to fit your XML format.