The only ways I could think of is to create a copy of the current counter and push it forward (which obviously becomes pretty ugly) or use the .skip() method from Linq to create an enumerable that works in front and then concatenates both using some kind of a combination method that you will again need to determine yourself.
At another point: in order to have a meaningful order of elements, you probably want to use System.Generics.SortedDictionary instead of the standard one.
This method should work to combine the two ienumerables given an adequate adder method
public static IEnumerable<TResult> Combine<TParam1, TParam2, TResult>(this IEnumerable<TParam1> self, IEnumerable<TParam2> other, Func<TParam1, TParam2, TResult> combiner) { using(var first=self.GetEnumerator()) using (var second = other.GetEnumerator()) { while (first.MoveNext() && second.MoveNext()) yield return combiner(first.Current, second.Current); } }
I canβt guarantee that this will work just like that, because I had to cut the code from the source fragment
Edit: with a little thought on this, this might be what you want: (unfortunately in C #, since my vb is not so good):
skippedEnumerable = myEnumerable; myEnumerable.Select(item => {skippedEnumerable = skippedEnumerable.Skip(1); return new KeyValuePair<T, IEnumerable<T>>(item, skippedEnumerable )});
This will give you a couple of the current item and an enumerable run at the current position, so you can use .ElementAt () to easily offset to that enumerated. This may cause the enumerations to be deep enough, so it is probably (or maybe not due to O (n ^ 2)) it is better to use myEnumerable.Skipe(index) directly;
source share