System.IO.StringReader.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 override 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);
            }
            if (_s == null)
            {
                throw new ObjectDisposedException(null, SR.ObjectDisposed_ReaderClosed);
            }

            int n = _length - _pos;
            if (n > 0)
            {
                if (n > count)
                {
                    n = count;
                }

                _s.CopyTo(_pos, buffer, index, n);
                _pos += n;
            }
            return n;
        }

Same methods

StringReader::Read ( ) : int

Usage Example

Exemple #1
0
        static void Main(string[] args)
        {
            StringWriter w = new StringWriter();
            w.WriteLine("Sing a song of {0} pence", 6);
            string s = "A pocket full of rye";
            w.Write(s);
            w.Write(w.NewLine);
            w.Write(string.Format(4 + " and " + 20 + " blackbirds"));
            w.Write(new StringBuilder(" baked in a pie"));
            w.WriteLine();
            Console.WriteLine(w);

            StringBuilder sb = w.GetStringBuilder();
            int i = sb.Length;
            sb.Append("The birds began to sing");
            sb.Insert(i, "when the pie was opened\n");
            sb.AppendFormat("\nWasn't that a {0} to set before the king", "dainty dish");
            Console.WriteLine(w);

            Console.WriteLine();
            StringReader r = new StringReader(w.ToString());
            string t = r.ReadLine();
            Console.WriteLine(t);
            Console.Write((char)r.Read());
            char[] ca = new char[37];
            r.Read(ca, 0, 19);
            Console.Write(ca);
            Console.WriteLine(r.ReadToEnd());

            r.Close();
            w.Close();
            Console.ReadLine();
        }
All Usage Examples Of System.IO.StringReader::Read