Exception związany z mscorlib.dll

0

Wersja pierwsza kodu działa poprawnie, wersja druga pokazuje błąd:

An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
Może mi ktoś to wytłumaczyć, nie bardzo wiem jak korzystać z StreamWriter i o co chodzi z tym błędem?


    static void Main(string[] args)
    {

        int n = Convert.ToInt32(Console.ReadLine());

        int result = factorial(n);
        Console.WriteLine(result);
        Console.ReadKey();
   
    }

Ten kod nie dziala:

class Solution
{

    // Complete the factorial function below.
    static int factorial(int n)
    {
        if (n<2)
        {
            return 1;
        }
        else
        {
            return n * factorial(n - 1);
        }
       
    }

    static void Main(string[] args)
    {
        TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);

        int n = Convert.ToInt32(Console.ReadLine());

        int result = factorial(n);

        textWriter.WriteLine(result);

        textWriter.Flush();
        textWriter.Close();


       
    }
}
0

Masz w ogóle taką zmienną środowiskową: OUTPUT_PATH ??

0

w sumie to nie..
ale jak ja stworzylem jest ten sam blad

0

Nazwę pliku tez musisz podać

  TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH")+"\\plik.txt", true);

1 użytkowników online, w tym zalogowanych: 0, gości: 1