如何转到 IEnumerable 中的特定项目 [英] How to go to particular Item in IEnumerable
问题描述
我有 IEnumerable,其中包含数字数据.
I have IEnumerable which contains number Data inside it.
编辑IEnumerable 来自 System.Collection.Ienumerable 指令.
Edit The IEnumerable is from System.Collection.Ienumerable directive.
附上Viual Studio的快照,包含数据的枚举:
Attached the snapShot of Viual Studio, Enum that Contains Data:
替代文字 http://www.freeimagehosting.net/uploads/bd72c6c310.jpg
简单介绍一下上图,eLevelData 是 IEnumerable
变量,我的数据在其中.
Just to brief about the above image, eLevelData is the IEnumerable
variable, in which I have my data .
现在我想转到索引 4 或 5 处的数据,但我不想使用 foreach 循环.请提出任何建议.
Now I want to go to the data at index 4 or 5, but I don't want to use foreach loop. Any suggestions please.
谢谢,
苏珊
推荐答案
var item = eLevelData.ElementAt(index);
如果您的集合类型为 IEnumerable
而不是 IEnumerable
,则您需要先使用 Cast
扩展方法调用 ElementAt 例如
If your collection is typed as IEnumerable
instead of IEnumerable<T>
you'll need to use the Cast
extension method before you can call ElementAt e.g.
var item = eLevelData.Cast
这篇关于如何转到 IEnumerable 中的特定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!