Selaa lähdekoodia

Added WithIndex for enumerables

Kenric Nugteren 1 vuosi sitten
vanhempi
commit
60a5928fbe
1 muutettua tiedostoa jossa 10 lisäystä ja 0 poistoa
  1. 10 0
      InABox.Core/CoreUtils.cs

+ 10 - 0
InABox.Core/CoreUtils.cs

@@ -2856,6 +2856,16 @@ namespace InABox.Core
             }
         }
 
+        public static IEnumerable<KeyValuePair<int, T>> WithIndex<T>(this IEnumerable<T> enumerable)
+        {
+            int i = 0;
+            foreach(var obj in enumerable)
+            {
+                yield return new KeyValuePair<int, T>(i, obj);
+                ++i;
+            }
+        }
+
         #endregion
 
     }