当前位置: 首页 > 编程语言 > C#

Path.Combine()在盘符后不加目录分隔符分享

时间:2023-04-11 01:11:56 C#

Path.Combine()在盘符后不加目录分隔符我的Path.CombinePath.Combine方法正确使用?我使用Path.Combine(string[])得到这个结果:C:Users\Admin\AppData\Roaming\TestProject\Connections.xml这是不太理想的代码的期望结果:注释掉的代码产生的结果:C:\Users\Admin\AppData\Roaming\TestProject\Connections.xml请注意第一个路径中驱动器号后缺少的\。旧方法(手动添加反斜杠,注释掉)工作正常,但我很确定它不会在Linux下工作,或者如果用单声道编译的话。字符串[]TempSave=Application.UserAppDataPath.Split(Path.DirectorySeparatorChar);string[]DesiredPath=newstring[TempSave.Length-2];for(inti=0;i