瀏覽代碼

Added new ToArray<> utility function

Kenric Nugteren 1 周之前
父節點
當前提交
0262f21688
共有 1 個文件被更改,包括 11 次插入0 次删除
  1. 11 0
      InABox.Core/CoreUtils.cs

+ 11 - 0
InABox.Core/CoreUtils.cs

@@ -2654,6 +2654,17 @@ namespace InABox.Core
             }
             return to;
         }
+        public static U[] ToArray<T, U>(this ICollection<T> from, Func<T, U> mapFunc)
+        {
+            var to = new U[from.Count];
+            var i = 0;
+            foreach(var item in from)
+            {
+                to[i] = mapFunc(item);
+                ++i;
+            }
+            return to;
+        }
 
         public static List<U> ToList<T, U>(this IList<T> from, Func<T, U> mapFunc)
         {