我有一个 XML 文件,我从中解析一些内容以显示在列表中:
班级:
public class SampleClass
{
public string Sample {get; set;}
public string Definite {get; set;}
public string Random {get; set;}
}
XML 文件示例:
<Question>
<Sample>This is sample 1</Sample>
<Definite>Answer 1</Definite>
</Question>
<Question>
<Sample>This is sample 2</Sample>
<Definite>Answer 2</Definite>
</Question>
...
目前,我正在轻松解析列表中的内容并制作此列表。
_list = xmlDoc.Descendants("Question")
.Select(
q => new SampleClass
{
Sample = q.Element("Sample").Value,
Definite = q.Element("Definite").Value
})
.ToList();
但是,在列表中,我想包含另一个要从 XML 文件中以随机顺序解析的元素,例如:
SampleClass list Sample Definite Random
^ ^ ^
List element 1: This is sample 1, Answer 1, Answer5
List element 2: This is sample 2, Answer 2, Answer1
List element 3: This is sample 3, Answer 3, Answer4 ...
我想问一下如何Random
在解析时将这个元素包含在列表中,以便从节点中q.Random
随机分配一个?<Definite> Value </Definite>
Question
列表中的随机副本是不可接受的。