如何使用xpath在Linq中使用OrderBy

时间:2010-09-28 11:03:21

标签: c# linq

我有2 IEnumerable<XPathNavigator>,我想按子值对其进行排序。

item1 = from XPathNavigator item in iterator1 select item;  
item2 = from XPathNavigator item in iterator2 select item;

item1 = item1.Union(item2);

item1.OrderBy(res => int.Parse(GetNavigatorValue(res, "./item[@value='ParentId']")));

static string GetNavigatorValue(XPathNavigator iterator, string xpath)
{

   XPathNodeIterator inner = iterator.Select(xpath);
   inner.MoveNext();
   return inner.Current.Value;
}

它不起作用。

如果需要按xpath对其进行排序,如何在Linq中使用OrderBy

谢谢, user460397

1 个答案:

答案 0 :(得分:0)

这是问题吗?不应该是

item1 = item1.OrderBy( ... );