Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#值不能使用Path.Combine为空_C#_.net_Directory_Path - Fatal编程技术网

C#值不能使用Path.Combine为空

C#值不能使用Path.Combine为空,c#,.net,directory,path,C#,.net,Directory,Path,我正试图使用C#控制台构建一个数据库,但我遇到了一个错误,似乎找不到问题所在。问题出在我的查询函数中,当我试图根据用户输入定义路径时。本质上,它查看用户文件夹中的给定文件夹,以及其中包含数据库信息的文件的另一个子文件夹。我使用Path.Combine函数在我的代码中动态定义路径,但是我得到了以下错误 ArgumentNullException:值不能为null。(参数“路径3”) 即使所有字符串都已定义且不为空 这是代码行的样子: path = Path.Combine(Info.path, "

我正试图使用C#控制台构建一个数据库,但我遇到了一个错误,似乎找不到问题所在。问题出在我的查询函数中,当我试图根据用户输入定义路径时。本质上,它查看用户文件夹中的给定文件夹,以及其中包含数据库信息的文件的另一个子文件夹。我使用Path.Combine函数在我的代码中动态定义路径,但是我得到了以下错误

ArgumentNullException:值不能为null。(参数“路径3”)

即使所有字符串都已定义且不为空

这是代码行的样子:

path = Path.Combine(Info.path, "infolder", classrooms.inventory, classrooms.geninv, userinput)
下面是path参数中的字符串引用的所有代码:

class classrooms
{
    public static string Teacher;
    public static string Roomnumber;
    public static string Changes;
    public static string inventory = "inventory";
    public static string geninv = "GenInv";
    public static string classinv = "ClassInv";
}

如有必要,我可以附上我的完整代码

我想出来了。
pathcombine函数在代码的另一个实例中使用的是一个定义不正确的字符串,当我重用path.combine函数时,它就被捕获了。感谢所有的答案,如果没有所有的输入,我不会想到去看它。

我猜
userinput
null
@ThomasSchremser否,因为userinput是由pathcombine函数前面的代码行中的readline函数定义的。字符串userinput=Console.ReadLine();错误表明
path3
参数为
null
。当您调用
路径时,请确保
教室.inventory
(位于
路径3
的位置)不为空。Combine
@MattU它不为空,这就是此处的问题所在。我在课堂上用公共静态字符串inventory=“inventory”定义了它;错误不在Path.Combine中。抛出异常的可能是您的
类型构造函数。函数
类型构造函数。这是因为Roomnumber字符串未在类中定义。显然,它必须分配给一个字符串。
class Info
    {
        public static string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
    }