Fill Array with Element - CSharp System

CSharp examples for System:Array Operation

Description

Fill Array with Element

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  w  w  w. j  a v  a 2 s  .c om

public class Main{
        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;
            }
        }
}

Related Tutorials