英語で読む

次の方法で共有


Console.In プロパティ

定義

標準入力ストリームを取得します。

[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.IO.TextReader In { get; }
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.IO.TextReader In { get; }
public static System.IO.TextReader In { get; }

プロパティ値

標準入力ストリームを表す TextReader オブジェクト。

属性

次の例は、 プロパティの使用方法を In 示しています。

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

注釈

このプロパティは、既定で標準入力ストリームに設定されます。 このプロパティは、 メソッドを使用して別のストリームに SetIn 設定できます。

標準入力ストリームに対する読み取り操作は同期的に実行されます。 つまり、指定された読み取り操作が完了するまでブロックされます。 これは、 などのReadLineAsync非同期メソッドが、 プロパティによってIn返されるオブジェクトでTextReader呼び出された場合でも当てはまります。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

こちらもご覧ください