System.Collections.ArrayList.RemoveRange C# (CSharp) Method

RemoveRange() public method

public RemoveRange ( int index, int count ) : void
index int
count int
return void
        public virtual void RemoveRange(int index, int count)
        {
            if (index < 0)
                throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
            if (count < 0)
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            if (_size - index < count)
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            Contract.Ensures(Count >= 0);
            //Contract.Ensures(Count == Contract.OldValue(Count) - count);
            Contract.EndContractBlock();

            if (count > 0)
            {
                int i = _size;
                _size -= count;
                if (index < _size)
                {
                    Array.Copy(_items, index + count, _items, index, _size - index);
                }
                while (i > _size) _items[--i] = null;
                _version++;
            }
        }

Usage Example

Example #1
0
    private char[] Read_byte_int_int(SerialPort com)
    {
        System.Collections.ArrayList receivedBytes = new System.Collections.ArrayList();
        byte[] buffer         = new byte[DEFAULT_READ_BYTE_ARRAY_SIZE];
        int    totalBytesRead = 0;
        int    numBytes;

        while (true)
        {
            try
            {
                numBytes = com.Read(buffer, 0, buffer.Length);
            }
            catch (TimeoutException)
            {
                break;
            }

            receivedBytes.InsertRange(totalBytesRead, buffer);
            totalBytesRead += numBytes;
        }

        if (totalBytesRead < receivedBytes.Count)
        {
            receivedBytes.RemoveRange(totalBytesRead, receivedBytes.Count - totalBytesRead);
        }

        return(com.Encoding.GetChars((byte[])receivedBytes.ToArray(typeof(byte))));
    }
All Usage Examples Of System.Collections.ArrayList::RemoveRange