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