Advertisement
Guest User

Untitled

a guest
Jan 4th, 2017
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.35 KB | None | 0 0
  1. public static IEnumerable<KeyValuePair<int, T>> Enumerate<T>(this IEnumerable<T> collection, int startIndex=0)
  2. {
  3.     foreach (var item in collection) { yield return new KeyValuePair<int, T>(startIndex++, item); }
  4. }
  5.  
  6. Use:
  7.     foreach (var idx_val in Enumerate(Iterable))
  8.     {
  9.         int idx = idx_val.Key;
  10.         var el = idx_val.Value;
  11.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement