I do not know anything in the structure that does this, but it is quite simple to implement it:
// Note: start is inclusive, end is exclusive (as is conventional // in computer science) public static void Fill<T>(T[] array, int start, int end, T value) { if (array == null) { throw new ArgumentNullException("array"); } if (start < 0 || start >= end) { throw new ArgumentOutOfRangeException("fromIndex"); } if (end >= array.Length) { throw new ArgumentOutOfRangeException("toIndex"); } for (int i = start; i < end; i++) { array[i] = value; } }
Or, if you want to specify a counter instead of a start / end:
public static void Fill<T>(T[] array, int start, int count, T value) { if (array == null) { throw new ArgumentNullException("array"); } if (count < 0) { throw new ArgumentOutOfRangeException("count"); } if (start + count >= array.Length) { throw new ArgumentOutOfRangeException("count"); } for (var i = start; i < start + count; i++) { array[i] = value; } }
source share