Browse Source

Added WithIndex for enumerables

Kenric Nugteren 1 năm trước cách đây
mục cha
commit
60a5928fbe
1 tập tin đã thay đổi với 10 bổ sung0 xóa
  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
 
     }