如何到具体项目中的IEnumerable [英] How to go to particular Item in IEnumerable

查看:190
本文介绍了如何到具体项目中的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工作室,枚举包含数据的快照:

Attached the snapShot of Viual Studio, Enum that Contains Data:

只是简单地介绍关于上面的图片,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.

谢谢

Subhen

推荐答案

VAR项目= eLevelData.ElementAt(指数);

如果您的收藏类型为的IEnumerable 而不是的IEnumerable< T> 则需要使用之前,你可以打电话投的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项目= eLevelData.Cast&LT; RMSRequestProcessor.RMSMedia&GT;()的ElementAt(指数)

这篇关于如何到具体项目中的IEnumerable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆