Slice an array - CSharp System

CSharp examples for System:Array Operation

Description

Slice an array

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w  w w.ja  va 2s  .  com*/

public class Main{
        public static T[] Slice<T>(T[] Arr, int Offset, int Length)
        {
            if (Offset < 0)
                Offset = Arr.Length + Offset;
            T[] newArr = new T[Arr.Length - Length];
            System.Array.Copy(Arr, 0, newArr, 0, Offset);
            System.Array.Copy(Arr, Offset + Length, newArr, Offset, Arr.Length - Offset - Length);
            return newArr;
        }
}

Related Tutorials