从IEnumerable中的任何点访问一系列元素 [英] Accessing a range of elements from any point in an IEnumerable
本文介绍了从IEnumerable中的任何点访问一系列元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这种方法:
private IEnumerable<XElement> ReadTransactions(string file_name)
{
using (var reader = XmlReader.Create(file_name + ".xml"))
{
while (reader.ReadToFollowing("transaction", "urn:namepsaceUri"))
{
using (var subtree = reader.ReadSubtree())
{
yield return XElement.Load(subtree);
}
}
}
}
此方法从XML文件读取.但是,我不需要同时使用XML文件中的所有节点.
This method reads from an XML file. However, I don't need all of the nodes in the XML file at same time.
我想一次让他们十个.
我尝试使用XPathSelectElements,但这会获取所有节点,然后需要遍历它们.
I tried working with XPathSelectElements, but that gets all the nodes, and then I need to iterate through them.
那么,有没有一种方法可以从XML文件中获取40-50个节点?我想修改ReadTransactions
-具有另一个输入参数(在这种情况下为40),而不是所有元素,它将仅返回10?
So, is there a way to get the nodes from the XML file which are 40-50? I want to modify ReadTransactions
- to have another input parameter (40 in this case), and instead of all the elements, it will return just 10?
推荐答案
var items = ReadTransactions(file_name).Skip(40).Take(10);
这篇关于从IEnumerable中的任何点访问一系列元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文