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

CopyTo() public method

public CopyTo ( Array array ) : void
array Array
return void
        public virtual void CopyTo(Array array)
        {
            CopyTo(array, 0);
        }

Same methods

ArrayList::CopyTo ( Array array, int arrayIndex ) : void
ArrayList::CopyTo ( int index, Array array, int arrayIndex, int count ) : void

Usage Example

        /// <summary>
        /// Reads byte[] line from stream.
        /// </summary>
        /// <returns>Return null if end of stream reached.</returns>
        public byte[] ReadLine()
        {
            ArrayList lineBuf  = new ArrayList();
            byte      prevByte = 0;

            int currByteInt = m_StrmSource.ReadByte();
            while(currByteInt > -1){
                lineBuf.Add((byte)currByteInt);

                // Line found
                if((prevByte == (byte)'\r' && (byte)currByteInt == (byte)'\n')){
                    byte[] retVal = new byte[lineBuf.Count-2];    // Remove <CRLF>
                    lineBuf.CopyTo(0,retVal,0,lineBuf.Count-2);

                    return retVal;
                }

                // Store byte
                prevByte = (byte)currByteInt;

                // Read next byte
                currByteInt = m_StrmSource.ReadByte();
            }

            // Line isn't terminated with <CRLF> and has some chars left, return them.
            if(lineBuf.Count > 0){
                byte[] retVal = new byte[lineBuf.Count];
                lineBuf.CopyTo(0,retVal,0,lineBuf.Count);

                return retVal;
            }

            return null;
        }
All Usage Examples Of System.Collections.ArrayList::CopyTo