Esporta (0) Stampa
Espandi tutto

Proprietà Console.Error

Consente di ottenere il flusso di output di errore standard.

Spazio dei nomi: System
Assembly: mscorlib (in mscorlib.dll)

public static TextWriter Error { get; }
/** @property */
public static TextWriter get_Error ()

public static function get Error () : TextWriter

Valore proprietà

Oggetto TextWriter che rappresenta il flusso di output di errore standard.

La proprietà è impostata sul flusso di errore standard per impostazione predefinita. Questa proprietà può essere impostata su un altro flusso con il metodo SetError.

Nell'esempio di codice riportato di seguito viene illustrato l'utilizzo della proprietà Error.

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

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 per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

.NET Framework

Supportato in: 2.0 1.1 1.0

.NET Compact Framework

Supportato in: 2.0

Aggiunte alla community

AGGIUNGI
Mostra:
© 2014 Microsoft