Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.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#_Winforms - Fatal编程技术网

C# 为什么Path.Combine没有合并路径和文件?

C# 为什么Path.Combine没有合并路径和文件?,c#,winforms,C#,Winforms,我有以下代码: string log_file_name = @"\logger.txt"; string logger_file_to_read = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log"; string LoggerFile = Path.Combine(logger_file_to_read, log_file_name); 我使用了一个断点,我看到

我有以下代码:

string log_file_name = @"\logger.txt";
            string logger_file_to_read = Path.GetDirectoryName(Application.LocalUserAppDataPath) + @"\log";
            string LoggerFile = Path.Combine(logger_file_to_read, log_file_name);
我使用了一个断点,我看到:logger_file_to_read包含:

C:\Users\bout0\u 000\AppData\Local\Diagnostic\u Tool\u Blue\u Screen\Diagnostic Tool Blue Screen\log

该日志文件名包含:

\logger.txt

但是我看到LoggerFile只包含文件名:\logger.txt 没有目录

那是什么?

就在那里的:

例如,如果path2不包括根,如果path2不以分隔符或驱动器规格开头,则结果是两条路径的串联,中间带有分隔符。如果路径2包含根,则返回路径2

就在那里的:

例如,如果path2不包括根,如果path2不以分隔符或驱动器规格开头,则结果是两条路径的串联,中间带有分隔符。如果路径2包含根,则返回路径2


在文件名中删除反斜杠,如下所示:

string log_file_name = "logger.txt";

在文件名中删除反斜杠,如下所示:

string log_file_name = "logger.txt";
因此OP应该设置log_file_name=logger.txt;没有``所以OP应该设置log\u file\u name=logger.txt;没有``