Console.In 属性

定义

获取标准输入流。Gets the standard input stream.

public:
 static property System::IO::TextReader ^ In { System::IO::TextReader ^ get(); };
public static System.IO.TextReader In { get; }
member this.In : System.IO.TextReader
Public Shared ReadOnly Property In As TextReader

属性值

表示标准输入流的 TextReaderA TextReader that represents the standard input stream.

示例

下面的示例演示如何使用 In 属性。The following sample illustrates the use of the In property.

using namespace System;
using namespace System::IO;
int main()
{
   TextReader^ tIn = Console::In;
   TextWriter^ tOut = Console::Out;
   tOut->WriteLine( "Hola Mundo!" );
   tOut->Write( "What is your name: " );
   String^ name = tIn->ReadLine();
   tOut->WriteLine( "Buenos Dias, {0}!", name );
}

using System;
using System.IO;

class InTest {
    public static void Main() {

        TextReader tIn = Console.In;
        TextWriter tOut = Console.Out;

        tOut.WriteLine("Hola Mundo!");
        tOut.Write("What is your name: ");
        String name = tIn.ReadLine();

        tOut.WriteLine("Buenos Dias, {0}!", name);
    }
}
Imports System.IO

Class InTest
    
    Public Shared Sub Main()
        Dim tIn As TextReader = Console.In
        Dim tOut As TextWriter = Console.Out
        
        
        tOut.WriteLine("Hola Mundo!")
        tOut.Write("What is your name: ")
        Dim name As [String] = tIn.ReadLine()
        
        tOut.WriteLine("Buenos Dias, {0}!", name)
    End Sub
End Class

注解

默认情况下,此属性设置为标准输入流。This property is set to the standard input stream by default. 此属性可设置为具有 SetIn 方法的另一个流。This property can be set to another stream with the SetIn method.

对标准输入流执行的读取操作同步执行。Read operations on the standard input stream execute synchronously. 也就是说,它们将被阻止,直到指定的读取操作完成。That is, they block until the specified read operation has completed. 即使在 In 属性返回的 TextReader 对象上调用异步方法(如 ReadLineAsync),也是如此。This is true even if an asynchronous method, such as ReadLineAsync, is called on the TextReader object returned by the In property.

适用于

另请参阅