Console.Error 속성
표준 오류 출력 스트림을 가져옵니다.
네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Shared ReadOnly Property Error As TextWriter
‘사용 방법
Dim value As TextWriter
value = Console.Error
public static TextWriter Error { get; }
public:
static property TextWriter^ Error {
TextWriter^ get ();
}
/** @property */
public static TextWriter get_Error ()
public static function get Error () : TextWriter
속성 값
표준 오류 출력 스트림을 나타내는 TextWriter입니다.
설명
기본적으로 이 속성은 표준 오류 스트림으로 설정되어 있습니다. SetError 메서드를 사용하여 이 속성을 다른 스트림으로 설정할 수 있습니다.
예제
다음 코드 예제에서는 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;
}
}
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0에서 지원