[英]Visual Studio environmental variable OUTPUT_PATH
I'm getting this error trying to solve simple problem using Visual Studio 2019我在尝试使用 Visual Studio 2019 解决简单问题时遇到此错误
System.ArgumentNullException: 'Value cannot be null.
System.ArgumentNullException: '值不能是 null。 Parameter name: path'
参数名称:路径'
This is the line of code causing the error:这是导致错误的代码行:
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
Is it something wrong with my environment variable?我的环境变量有问题吗? If that so, how can I fix this?
如果是这样,我该如何解决这个问题?
Full code below:完整代码如下:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution
{
/*
* Complete the simpleArraySum function below.
*/
static int simpleArraySum(int[] ar)
{
/*
* Write your code here.
*/
return 0;
}
static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
int arCount = Convert.ToInt32(Console.ReadLine());
int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp));
int result = simpleArraySum(ar);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
You shouldn't use the environment variable "OUTPUT_PATH".您不应该使用环境变量“OUTPUT_PATH”。 It's not a standard variable on every machine.
它不是每台机器上的标准变量。
Try write to a folder relative to the exe or some other folders such documents in "%userprofile%"尝试写入相对于 exe 的文件夹或“%userprofile%”中的其他一些文件夹,例如文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.