2010-10-01 46 views
2

我在与返回LINQ查询的.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) 

是正确的,因为它返回XElements我想要的清单(项目1 - 4,基数0),但我真的只需要这些XElement的.Value的字符串列表。也许我只是在这里密集,但我在chapterTitles查询中尝试过的任何内容都无法工作(使用.ToList.ToString附加等)。 details.<Vector>.<Item>.Skip(1).Take(4).Value只返回第一个XElement的值。

有什么想法?

回答

3

您需要执行Select将结果从XElement s转换为string s。

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 
+0

唉,我怎么会这么密集!像魅力一样工作,谢谢!需要更多的人接受,所以我会做。 – 2010-10-01 18:49:35