2000年代: .NET
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2021/02/26 17:14 UTC 版)
「標準ストリーム」の記事における「2000年代: .NET」の解説
C#などの.NET言語では、標準ストリームはSystem.Console.In (stdin)、System.Console.Out (stdout)、System.Console.Error (stderr) で参照される。stdinおよびstdoutストリームの基本的な読み書きの場合、クラスSystem.Consoleを使って直接アクセスすることもできる(つまり、System.Console.Out.WriteLine()の代わりにSystem.Console.WriteLine()を使える)。 System.Console.In、System.Console.Out、System.Console.Errorは System.IO.TextReader (stdin) および System.IO.TextWriter (stdout, stderr) オブジェクトであり、テキストベースの標準ストリームにしかアクセスできない。標準ストリームへの完全バイナリアクセスにはSystem.IO.Streamオブジェクトを使う必要があり、それぞれSystem.Console.OpenStandardInput()、System.Console.OpenStandardOutput()、System.Console.OpenStandardError()で得られる。 // C# examplepublic static int Main(string[] args){ try { string s = System.Console.In.ReadLine(); double number = double.Parse(s); System.Console.Out.WriteLine("Number is: {0:F3}", number); return 0; // If Parse() threw an exception } catch (System.ArgumentNullException) { System.Console.Error.WriteLine("No number was entered!"); } catch (System.FormatException) { System.Console.Error.WriteLine("The specified value is not a valid number!"); } catch (System.OverflowException) { System.Console.Error.WriteLine("The specified number is too big!"); } return -1;} ' Visual Basic .NET examplePublic Function Main() As Integer Dim number As Double Dim s As String Try s = System.Console.In.ReadLine() number = CDbl(s) System.Console.Out.WriteLine("Number is: {0:F3}", number) Return 0 Catch e As System.InvalidCastException ' if CDbl() threw an exception System.Console.Error.WriteLine("No number was entered!") Return 1 End TryEnd Function System.Diagnostics.Processクラスを使うと、そのインスタンスプロパティStandardInput、StandardOutput、StandardErrorを使ってそのプロセスの標準ストリームにアクセスできる。
※この「2000年代: .NET」の解説は、「標準ストリーム」の解説の一部です。
「2000年代: .NET」を含む「標準ストリーム」の記事については、「標準ストリーム」の概要を参照ください。
- 2000年代: .NETのページへのリンク