我在返回 .Value
的字符串列表时遇到问题Linq 查询的:
Dim details = <Details>
<Vector size="5">
<Item>Syntactic Structures</Item>
<Item>Introduction</Item>
<Item>The Independence of Grammar</Item>
<Item>An Elementary Linguistic Theory</Item>
<Item>Phrase Structure</Item>
</Vector>
</Details>
Dim chapterTitles = details.<Vector>.<Item>.Skip(1).Take(4)
正确的是,它返回我想要的 XElement 列表(项目 1 - 4,基数 0),但我实际上只需要 .Value
的字符串列表。这些 XElements。也许我只是在这里很密集,但是我在 chapterTitles
中尝试过的任何东西查询不起作用(附加 .ToList.ToString 等)。 details.<Vector>.<Item>.Skip(1).Take(4).Value
仅返回第一个 XElement 的值。
有什么想法吗?
最佳答案
您需要执行 Select
将结果从 XElement
转换为 string
。
Dim chapterTitles = details.<Vector>.<Item>.Skip(1).Take(4).Select(Function(item) item.Value)
或
Dim chapterTitles = From item In details.<Vector>.<Item>.Skip(1).Take(4) _
Select item.Value
关于.net - 将结果值转换为 Linq 中的字符串列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3842141/