.NET中的两个方向列表枚举器 [英] Two directional list Enumerator in .NET
问题描述
在我的c#应用程序中,我有一个列表,可以使用枚举器进行导航.它非常适合在列表中前进,但是Enumerator类没有MoveBack方法.
In my c# app, I've got a list that I navigate with an Enumerator. It works great for moving forward through the list, but the Enumerator class doesn't have a MoveBack method.
是否存在具有MoveBack方法的其他类,还是我需要编写自己的类?
Is there different class that has a MoveBack method, or do I need to write my own?
推荐答案
任何使用IEnumerator接口定义的枚举器都必须在定义第一个元素之前开始,并迭代整个集合.简而言之:它们不支持向后遍历.
Any enumerators using the IEnumerator interface by definition must start before the first element and iterate forwards through the collection. In short: they don't support backwards traversal.
如果要向后遍历,则需要编写自己的枚举函数,使您可以从任何位置开始.
If you want backwards traversal you'll need to write your own enumeration functions that allow you start anywhere you want.
这篇关于.NET中的两个方向列表枚举器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!