System.IO.TextReader.Read C# (CSharp) Méthode

Read() public méthode

public Read ( char buffer, int index, int count ) : int
buffer char
index int
count int
Résultat int
        public virtual int Read(char[] buffer, int index, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
            }
            if (buffer.Length - index < count)
            {
                throw new ArgumentException(SR.Argument_InvalidOffLen);
            }

            int n = 0;
            do
            {
                int ch = Read();
                if (ch == -1)
                {
                    break;
                }
                buffer[index + n++] = (char)ch;
            } while (n < count);
            return n;
        }

Same methods

TextReader::Read ( ) : int

Usage Example

		public static string CalculateIndent(TextReader code, int line, bool tabsToSpaces = false, int indentWidth = 4)
		{
			if(line < 2)
				return string.Empty;
			
			var eng = new IndentEngine(DFormattingOptions.CreateDStandard(), tabsToSpaces, indentWidth);
			
			int curLine = 1;
			const int lf = (int)'\n';
			const int cr = (int)'\r';
			int c;
			while((c = code.Read()) != -1)
			{
				if(c == lf || c == cr)
				{
					if(c == cr && code.Peek() == lf)
						code.Read();
					
					if(++curLine > line)
						break;
				}
				
				eng.Push((char)c);
			}
			
			return eng.ThisLineIndent;
		}
All Usage Examples Of System.IO.TextReader::Read