Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static IEnumerable<KeyValuePair<int, T>> Enumerate<T>(this IEnumerable<T> collection, int startIndex=0)
- {
- foreach (var item in collection) { yield return new KeyValuePair<int, T>(startIndex++, item); }
- }
- Use:
- foreach (var idx_val in Enumerate(Iterable))
- {
- int idx = idx_val.Key;
- var el = idx_val.Value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement