如何在 C# 中加入两条路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/961704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:18:52  来源:igfitidea点击:

How do I join two paths in C#?

c#filepath

提问by Geo

How do I join two file paths in C#?

如何在 C# 中加入两个文件路径?

采纳答案by Jose Basilio

You have to use Path.Combine()as in the example below:

您必须使用Path.Combine()如下例所示:

string basePath = @"c:\temp";
string filePath = "test.txt";
string combinedPath = Path.Combine(basePath, filePath); 
// produces c:\temp\test.txt

回答by Cameron MacFarland

System.IO.Path.Combine()is what you need.

System.IO.Path.Combine()正是您所需要的。

Path.Combine(path1, path2);