Console.In Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the standard input stream.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public static TextReader In {
	[HostProtectionAttribute(SecurityAction.LinkDemand, UI = true)]
	get;
}

Property Value

Type: System.IO.TextReader

A TextReader that represents the standard input stream.

This property is set to the standard input stream by default. 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. This is true even if an asynchronous method, such as ReadLineAsync, is called on the TextReader object returned by the In property.

The following sample illustrates the use of the In property.

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);
    }
}

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: