public static int Copy <T>(MarshalArrayBase source, int sourceOffset, T[] destination, int destOffset, int count)
        {
            if (sourceOffset < 0 || destOffset < 0 || count < 0)
            {
                throw new ArgumentException("sourceOffset < 0 or destOffset < 0 or count < 0");
            }

            if (source.Length - sourceOffset < count)
            {
                count = source.Length - sourceOffset;
            }

            if (destination.Length - destOffset < count)
            {
                count = destination.Length - destOffset;
            }

            int srcIndex = sourceOffset;
            int dstIndex = destOffset;
            int srcEnd   = sourceOffset + count;

            while (srcIndex < srcEnd)
            {
                destination[dstIndex] = source.GetValue <T>(srcIndex);
                ++dstIndex;
                ++srcIndex;
            }
            return(count);
        }
        public static int LastIndexOf <T>(MarshalArrayBase source, T item, int beginIndex, int count)
        {
            if (beginIndex < 0 || count < 0)
            {
                throw new ArgumentException("beginIndex < 0 or count < 0");
            }

            if (beginIndex >= source.Length)
            {
                beginIndex = source.Length - 1;
            }

            if (beginIndex + 1 < count)
            {
                count = beginIndex + 1;
            }

            int end = beginIndex - count;
            int i   = beginIndex;

            while (i > end)
            {
                if (source.GetValue <T>(i).Equals(item))
                {
                    return(i);
                }
                --i;
            }

            return(-1);
        }