System.IO.StreamReader.ReadBlock C# (CSharp) Method

ReadBlock() public method

public ReadBlock ( char buffer, int index, int count ) : int
buffer char
index int
count int
return int
        public override int ReadBlock(char[] buffer, int index, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
            }
            if (index < 0 || count < 0)
            {
                throw new ArgumentOutOfRangeException(index < 0 ? nameof(index) : nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (buffer.Length - index < count)
            {
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            }
            if (_stream == null)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_ReaderClosed);
            }

            CheckAsyncTaskInProgress();

            return base.ReadBlock(buffer, index, count);
        }

Usage Example

Example #1
1
        /// <summary>
        /// Read the data file, skipping over data we're not interested in
        /// but parsing and storing the contents of the first data channel
        /// </summary>
        public static void Read()
        {
            OriginalValues.Clear();

            using (StreamReader r = new StreamReader("ECGSAMPLE.txt"))
            {
                int bytesRead = 0;
                char[] buffer = new char[24];

                while (!r.EndOfStream)
                {
                    bytesRead = r.ReadBlock(buffer, 0, 8);
                    if (bytesRead != 8)
                        break;

                    bytesRead = r.ReadBlock(buffer, 0, 24);
                    if (bytesRead != 24)
                        break;
                    else
                        ParseData(buffer);

                    bytesRead = r.ReadBlock(buffer, 0, 2);
                    if (bytesRead != 2)
                        break;
                }
            }

            return;
        }
All Usage Examples Of System.IO.StreamReader::ReadBlock