我不知道框架中执行此操作的任何内容,但是实现起来很容易:
// 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; }}或者,如果您要指定计数而不是开始/结束:
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; }}


