有关Path.Combine()方法
故名思义,其方法将两个字符串合并成一个合法的路径,
如合并Application.StartupPath和一个文件名,将输出正常的文件路径
但请注意,Application.StartupPath返回的路径并不包含"\",
实际使用后将自动加上反斜杠,如下为源码,其中Path.AltDirectorySeparatorChar几个值在代码后有给出,记录下下
public static string Combine(string path1, string path2)
{
if ((path1 == null) || (path2 == null))
{
throw new ArgumentNullException((path1 == null) ? "path1" : "path2");
}
CheckInvalidPathChars(path1);
CheckInvalidPathChars(path2);
if (path2.Length == 0)
{
return path1;
}
if (path1.Length == 0)
{
return path2;
}
if (IsPathRooted(path2))
{
return path2;
}
char ch = path1[path1.Length - 1];
if (((ch != DirectorySeparatorChar) && (ch != AltDirectorySeparatorChar)) && (ch != VolumeSeparatorChar))
{
return (path1 + DirectorySeparatorChar + path2);
}
return (path1 + path2);
}
// Path.AltDirectorySeparatorChar=/ // Path.DirectorySeparatorChar=\ // Path.PathSeparator=; // Path.VolumeSeparatorChar=: