为什么Path.Combine的驱动器盘符后不加Path.DirectorySeparatorChar? [英] Why Path.Combine doesn't add the Path.DirectorySeparatorChar after the drive designator?
本文介绍了为什么Path.Combine的驱动器盘符后不加Path.DirectorySeparatorChar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var actual = Path.Combine("c:", "filename");
var expected = @"c:\filename";
Assert.AreEqual(expected, actual);
结果
{Assert.AreEqual failed. Expected:<c:\filename>. Actual:<c:filename>.
为什么?
推荐答案
C:文件名
是一个有效的路径和不同于 C:\文件名
。 C:文件名
是文件中的
驱动而 c把当前目录下的文件名
: C:\文件名
是文件名
在该驱动器的根目录下的文件。显然,他们想保留指的是当前目录中的一些驱动器上的功能。
C:filename
is a valid path and is different from C:\filename
. C:filename
is the file filename
in the current directory on the C:
drive whereas C:\filename
is the file filename
in the root of that drive. Apparently they wanted to keep the functionality of refering to the current directory on some drive.
此行为被描述这里在MSDN
This behaviour is described here in MSDN
这篇关于为什么Path.Combine的驱动器盘符后不加Path.DirectorySeparatorChar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文