Console.Error プロパティとは? わかりやすく解説

Console.Error プロパティ

標準エラー出力ストリーム取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説
使用例使用例

Error プロパティ使用方法については、次のコード例参照してください

Public Class ExpandTabs
   Private Const tabSize As
 Integer = 4
   Private Const usageText As
 String = "Usage: EXPANDTABSEX inputfile.txt
 outputfile.txt"
   
   'Entry point which delegates to C-style main Private Function
   Public Overloads Shared
 Sub Main()
      System.Environment.ExitCode = Main(System.Environment.GetCommandLineArgs())
   End Sub
   
   Overloads Public Shared
 Function Main(args() As String)
 As Integer
      Dim writer As StreamWriter = Nothing
      Dim standardOutput As TextWriter = Console.Out
      
      If args.Length < 3 Then
         Console.WriteLine(usageText)
         Return 1
      End If
      
      Try
         writer = New StreamWriter(args(2))
         Console.SetOut(writer)
         Console.SetIn(New StreamReader(args(1)))
      Catch e As IOException
         Dim errorWriter As TextWriter = Console.Error
         errorWriter.WriteLine(e.Message)
         errorWriter.WriteLine(usageText)
         Return 1
      End Try
      Dim i As Integer
      i = Console.Read()
      While i <> -1 
         Dim c As Char =
 Convert.ToChar(i)
         If c = ControlChars.Tab Then
            Console.Write("".PadRight(tabSize, "
 "c))
         Else
            Console.Write(c)
         End If
         i = Console.Read()
      End While
      writer.Close()
      ' Recover the standard output stream so that a 
      ' completion message can be displayed.
      Console.SetOut(standardOutput)
      Console.WriteLine("EXPANDTABSEX has completed the processing
 of {0}.", args(0))
      Return 0
   End Function 'Main
End Class 'ExpandTabs
public class ExpandTabs {
    private const int tabSize
 = 4;
    private const string
 usageText = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
    public static int Main(string[]
 args) {
        StreamWriter writer = null;
        TextWriter standardOutput = Console.Out;

        if (args.Length < 2) {
            Console.WriteLine(usageText);
            return 1;
        }

        try {
            writer = new StreamWriter(args[1]);
            Console.SetOut(writer);
            Console.SetIn(new StreamReader(args[0]));
        }
        catch(IOException e) {
            TextWriter errorWriter = Console.Error;
            errorWriter.WriteLine(e.Message);
            errorWriter.WriteLine(usageText);
            return 1;            
        }
        int i;
        while ((i = Console.Read()) != -1) {
            char c = (char)i;
            if (c == '\t')
                Console.Write(("").PadRight(tabSize, ' '));
            else
                Console.Write(c);
        }
        writer.Close();
        // Recover the standard output stream so that a 
        // completion message can be displayed.
        Console.SetOut(standardOutput);
        Console.WriteLine("EXPANDTABSEX has completed the processing of {0}."
,
 args[0]);
        return 0;
    }
}
int main()
{
   const int tabSize = 4;
   array<String^>^args = Environment::GetCommandLineArgs();
   String^ usageText = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
   StreamWriter^ writer = nullptr;
   TextWriter^ standardOutput = Console::Out;
   if ( args->Length < 3 )
   {
      Console::WriteLine( usageText );
      return 1;
   }

   try
   {
      writer = gcnew StreamWriter( args[ 2 ] );
      Console::SetOut( writer );
      Console::SetIn( gcnew StreamReader( args[ 1 ] ) );
   }
   catch ( IOException^ e ) 
   {
      TextWriter^ errorWriter = Console::Error;
      errorWriter->WriteLine( e->Message );
      errorWriter->WriteLine( usageText );
      return 1;
   }

   int i;
   while ( (i = Console::Read()) != -1 )
   {
      Char c = (Char)i;
      if ( c == '\t' )
            Console::Write( ((String^)"")->PadRight( tabSize, ' ' )
 );
      else
            Console::Write( c );
   }

   writer->Close();
   
   // Recover the standard output stream so that a 
   // completion message can be displayed.
   Console::SetOut( standardOutput );
   Console::WriteLine( "EXPANDTABSEX has completed the processing of {0}.",
 args[ 0 ] );
   return 0;
}

public class ExpandTabs
{
    private static int tabSize
 = 4;
    private static String usageText =
        "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
    public static void main(String[]
 args)
    {
        StreamWriter writer = null;
        TextWriter standardOutput = Console.get_Out();
        if (args.length < 2) {
            Console.WriteLine(usageText);
            return;
        }
        try {
            writer = new StreamWriter(args[1]);
            Console.SetOut(writer);
            Console.SetIn(new StreamReader(args[0]));
        }
        catch (IOException e) {
            TextWriter errorWriter = Console.get_Error();
            errorWriter.WriteLine(e.get_Message());
            errorWriter.WriteLine(usageText);
            return;
        }
        int i;
        while (((i = Console.Read()) != -1)) {
            char c = (char)(i);
            if (c == '\t') {
                Console.Write("".PadRight(tabSize, ' '));
            }
            else {
                Console.Write(c);
            }
        }
        writer.Close();
        // Recover the standard output stream so that a 
        // completion message can be displayed.
        Console.SetOut(standardOutput);
        Console.WriteLine("EXPANDTABSEX has completed the processing of {0}."
,
            args[0]);
        return;
    } //main
} //ExpandTabs
public class ExpandTabs {
    private static var tabSize
 : int = 4;
    private static var usageText
 : String  = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
    public static function
 Main(args : String[]) : int {
        var writer : StreamWriter = null;
        var standardOutput : TextWriter = Console.Out;

        if (args.Length < 2) {
            Console.WriteLine(usageText);
            return 1;
        }

        try {
            writer = new StreamWriter(args[1]);
            Console.SetOut(writer);
            Console.SetIn(new StreamReader(args[0]));
        }
        catch(e : IOException) {
            var errorWriter : TextWriter = Console.Error;
            errorWriter.WriteLine(e.Message);
            errorWriter.WriteLine(usageText);
            return 1;            
        }
        var i : int;
        while ((i = Console.Read()) != -1) {
            var c : char = char(i);
            if (c == '\t')
                Console.Write(("").PadRight(tabSize, ' '));
            else
                Console.Write(c);
        }
        writer.Close();
        // Recover the standard output stream so that a 
        // completion message can be displayed.
        Console.SetOut(standardOutput);
        Console.WriteLine("EXPANDTABSEX has completed the processing of {0}."
,
 args[0]);
        return 0;
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からConsole.Error プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConsole.Error プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConsole.Error プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Console.Error プロパティ」の関連用語

Console.Error プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Console.Error プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS