Copy Subset from byte array - CSharp System

CSharp examples for System:Byte Array

Description

Copy Subset from byte array

Demo Code



public class Main{
        public static byte[] CopySubset(this byte[] source, int sourceStartIndex)
        {/*from w  ww  .  j av  a  2 s .  com*/
            byte[] destination = new byte[source.Length - sourceStartIndex];

            destination.CopyFrom(source, sourceStartIndex);

            return destination;

        }
        // requires destination to be pre-sized
        public static int CopyFrom(this sbyte[] destination, byte[] source, int sourceStartIndex)
        {
            for (int i = 0; i < destination.Length; i++)
            {
                destination[i] = (sbyte)source[sourceStartIndex++];
            }

            return sourceStartIndex;
        }
        // requires destination to be pre-sized
        public static int CopyFrom<T>(this T[] destination, T[] source, int sourceStartIndex)
        {
            for (int i = 0; i < destination.Length; i++)
            {
                destination[i] = source[sourceStartIndex++];
            }

            return sourceStartIndex;
        }
}

Related Tutorials