Custom property in C# with list need to access list for each item only

GameCode

New Member
I have a custom property called Questions the code is below.\[code\]public class Questions{ private List<Question> _q = new List<Question>(); public List<Question> Question { get { return _q; } } }public class Question{ public string Text { get; set; } public string Name { get; set; } public string Type { get; set; } public string Answer { get; set; } private List<string> _Options = new List<string>(); public List<string> Option { get { return _Options; } }}\[/code\]I then populate the property with the code below\[code\] XmlDocument doc = new XmlDocument(); Question q = new Question(); Questions qs = new Questions(); doc.Load(string.Format(@"questions.xml")); XmlNodeList list = doc.SelectNodes("/questions/question"); foreach (XmlNode node in list) { q.Text = node.SelectSingleNode("text").InnerText; q.Type = node.SelectSingleNode("type").InnerText; q.Name = node.SelectSingleNode("name").InnerText; XmlNodeList options = doc.SelectNodes("/questions/question/options"); foreach (XmlNode option in options) { q.Option.Add(option.SelectSingleNode("option").InnerText); } load.Visible = false; qa.Visible = true; qs.Question.Add(q); DisplayQuestion(qs); }\[/code\]Now when I try to access it with the code below I do not get the output I expect. And thus this is where I need help. The Sample XML is at the bottom\[code\] Label1.Text = q.Question[CurrentQ].Text; for (int i = 0; i < q.Question[CurrentQ].Option.Count; i++) { CheckBoxList1.Items.Add(q.Question[CurrentQ].Option); }\[/code\]XML:\[code\]<?xml version="1.0"?><questions> <question> <num>1</num> <type>radio</type> <text>Do you like cake?</text> <options> <option>Yes</option> <option>No</option> <option>Sometimes</option> </options> <name>cake</name> </question> <question> <num>2</num> <type>dropdown</type> <text>Do you like TV?</text> <options> <option>Yes</option> <option>No</option> <option>Sometimes</option> </options> <name>tv</name> </question> <question> <num>3</num> <type>checkbox</type> <text>What do you like?</text> <options> <option>Cake</option> <option>TV</option> <option>Flipper Reruns</option> </options> <name>flipper</name> </question></questions>\[/code\]And the output:What do you like?YesYesCakeYesYesCakeYesYesCake
 
Back
Top