我正在进行以下查询XDocument.最后一级.Descendants("Instance")产生一个表单的XElements列表:
<Instance>filepath1</Instance>
<Instance>filepath2</Instance>
<Instance>filepath3</Instance>
<Instance>filepath4</Instance>
Run Code Online (Sandbox Code Playgroud)
询问
List<string> fileNames = xDoc.Descendants("Main")
.FirstOrDefault()
.Descendants("SecondLevel")
.FirstOrDefault()
.Descendants("Instance")
.Select().ToList(); //this line is not correct. Need to get the instances node values as List<string>
Run Code Online (Sandbox Code Playgroud)
我怎么能存储的值filepath1,filepath2..在List<string>?
通过使用
....
.Descendants("Instance")
.Select(e => e.Value) // project to the string values
.ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
772 次 |
| 最近记录: |