为什么 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>.
为什么?
var actual = Path.Combine("c:", "filename");
var expected = @"c:\filename";
Assert.AreEqual(expected, actual);
Result
{Assert.AreEqual failed. Expected:<c:\filename>. Actual:<c:filename>.
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C:filename
是有效路径,与C:\filename
不同。C:filename
是C:
驱动器上当前目录中的文件filename
,而C:\filename
是该驱动器根目录中的文件filename
。显然他们想保留引用某个驱动器上当前目录的功能。MSDN 中此处描述了此行为
C:filename
is a valid path and is different fromC:\filename
.C:filename
is the filefilename
in the current directory on theC:
drive whereasC:\filename
is the filefilename
in the root of that drive. Apparently they wanted to keep the functionality of refering to the current directory on some drive.This behaviour is described here in MSDN
MSDN 似乎没有解释原因,但确实提供了有关内容的文档你看到的是:
MSDN doesn't seem to explain why, but does provide documentation on what you're seeing: