Browse Source

Added new ToArray<> utility function

Kenric Nugteren 1 week ago
parent
commit
0262f21688
1 changed files with 11 additions and 0 deletions
  1. 11 0
      InABox.Core/CoreUtils.cs

+ 11 - 0
InABox.Core/CoreUtils.cs

@@ -2654,6 +2654,17 @@ namespace InABox.Core
             }
             }
             return to;
             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)
         public static List<U> ToList<T, U>(this IList<T> from, Func<T, U> mapFunc)
         {
         {