【发布时间】:2010-07-01 20:20:02
【问题描述】:
xml 文件具有以下结构
<Root>
<Child value="A"/>
<Child value="B"/>
<Child value="C"/>
<Child value="D"/>
<Child value="E"/>
</Root>
和字典
Dictionary<int, string> dict = new Dictionary<int, string>();
我需要从文件中读取“value”的属性值,并将其添加到字典中作为值和索引作为键
喜欢
dict[1]="A"
dict[2]="B"
dict[3]="C"
dict[4]="D"
dict[5]="E"
为此,我使用 XML to LINQ 查询
dict = XDOC.Load(Application.StartupPath + "\\Test.xml").
Descendants("Child").ToDictionary("????", x => x.Attribute("Value").Value);
我必须用 wat 代替“????”在查询中
请给出解决方案
【问题讨论】: