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