Add Array.Fill apis
authorJames Ko <jamesqko@gmail.com>
Tue, 15 Nov 2016 23:55:49 +0000 (18:55 -0500)
committerJames Ko <jamesqko@gmail.com>
Tue, 15 Nov 2016 23:55:49 +0000 (18:55 -0500)
src/mscorlib/model.xml
src/mscorlib/src/System/Array.cs

index 1e041a8..2553560 100644 (file)
       <Member Name="CreateInstance(System.Type,System.Int64[])" />
       <Member Name="Empty&lt;T&gt;" />
       <Member Name="Exists&lt;T&gt;(T[],System.Predicate&lt;T&gt;)" />
+      <Member Name="Fill&lt;T&gt;(T[],T)" />
+      <Member Name="Fill&lt;T&gt;(T[],System.Int32,System.Int32,T)" />
       <Member Name="Find&lt;T&gt;(T[],System.Predicate&lt;T&gt;)" />
       <Member Name="FindAll&lt;T&gt;(T[],System.Predicate&lt;T&gt;)" />
       <Member Name="FindIndex&lt;T&gt;(T[],System.Int32,System.Int32,System.Predicate&lt;T&gt;)" />
index f191bf8..4e8d6f4 100644 (file)
@@ -1073,6 +1073,42 @@ namespace System {
             return Array.FindIndex(array, match) != -1;
         }
 
+        public static void Fill<T>(T[] array, T value)
+        {
+            if (array == null)
+            {
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+            }
+
+            for (int i = 0; i < array.Length; i++)
+            {
+                array[i] = value;
+            }
+        }
+
+        public static void Fill<T>(T[] array, int startIndex, int count, T value)
+        {
+            if (array == null)
+            {
+                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
+            }
+
+            if (startIndex < 0 || startIndex > array.Length)
+            {
+                ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
+            }
+
+            if (count < 0 || startIndex > array.Length - count)
+            {
+                ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
+            }
+
+            for (int i = startIndex, end = startIndex + count; i < end; i++)
+            {
+                array[i] = value;
+            }
+        }
+
         public static T Find<T>(T[] array, Predicate<T> match) {
             if( array == null) {
                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);