How to go to particular Item in IEnumerable

不想你离开。 提交于 2019-11-30 07:18:46

问题


I have IEnumerable which contains number Data inside it.

Edit The IEnumerable is from System.Collection.Ienumerable directive.

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

alt text http://www.freeimagehosting.net/uploads/bd72c6c310.jpg

Just to brief about the above image, eLevelData is the IEnumerable variable, in which I have my data .

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.

Thanks,

Subhen


回答1:


var item = eLevelData.ElementAt(index);

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<RMSRequestProcessor.RMSMedia>().ElementAt(index)




回答2:


Don't know much about what subset of .NET BCL/LINQ is available in Silverlight, but Skip should do the trick. But generally speaking it still uses foreach internally:

var item = eLevelData.Skip(4 /* or 5 */).First();


来源:https://stackoverflow.com/questions/2912079/how-to-go-to-particular-item-in-ienumerable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!