PART I
C h a p t e r 1 4 :
U s i n g I / O
369
PART IPART I
Enter some characters.
This is a test.
You entered: This is a test.
Although the
Console
methods are the easiest way to read from
Console.In
, you can
call methods on the underlying
TextReader
. For example, here is the preceding program
rewritten to use the
ReadLine( )
method defined by
TextReader
:
// Read a string from the keyboard, using Console.In directly.
using System;
class ReadChars2 {
static void Main() {
string str;
Console.WriteLine("Enter some characters.");
str = Console.In.ReadLine(); // call TextReader's ReadLine() method
Console.WriteLine("You entered: " + str);
}
}
Notice how
ReadLine( )
is now invoked directly on
Console.In
. The key point here is that
if you need access to the methods defined by the
Do'stlaringiz bilan baham: |