Procházet zdrojové kódy

Added WithIndex for enumerables

Kenric Nugteren před 1 rokem
rodič
revize
60a5928fbe
1 změnil soubory, kde provedl 10 přidání a 0 odebrání
  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
 
     }