Console.Read メソッド
標準入力ストリームから次の文字を読み取ります。
Public Shared Function Read() As Integer
[C#]
public static int Read();
[C++]
public: static int Read();
[JScript]
public static function Read() : int;
戻り値
入力ストリームの次の文字。または次の文字がない場合は -1。
例外
例外の種類 | 条件 |
---|---|
IOException | I/O エラーが発生しました。 |
解説
このメソッドは、読み取り操作が完了する (読み取り操作はユーザーが Enter キーを押した場合など) までは、制御を返しません。データを利用できる場合は、入力ストリームには、ユーザーが入力したデータと、その末尾に追加された環境依存の改行文字が格納されます。
使用例
Dim i As Integer
Dim c As Char
While True
i = Console.Read()
If i = - 1 Then
Exit While
End If
c = Microsoft.VisualBasic.Chr(i)
Console.WriteLine("Echo: {0}", c)
End While
Console.WriteLine("Done")
Return 0
[C#]
int i;
char c;
while (true)
{
i = Console.Read ();
if (i == -1) break;
c = (char) i;
Console.WriteLine ("Echo: {0}", c);
}
Console.WriteLine ("Done");
return 0;
[C++]
int i;
char c;
for(;;)
{
i = Console::Read ();
if (i == -1) break;
c = (char) i;
Console::WriteLine (S"Echo: {0}", __box(c));
}
Console::WriteLine (S"Done");
return 0;
[JScript]
var i : int;
var c : char;
while (true)
{
i = Console.Read ();
if (i == -1) break;
c = char(i);
Console.WriteLine ("Echo: {0}", c);
}
Console.WriteLine ("Done");
return 0;
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard
参照
Console クラス | Console メンバ | System 名前空間 | ReadLine | Write | WriteLine