正斜杠的命名空间常量

Rob*_*Rob 3 .net c# namespaces

什么是正斜杠"/"的.net名称空间常量

所以代替:

somePath + "/" + someFile
Run Code Online (Sandbox Code Playgroud)

我可以:

somePath + .net.namespace.forwardslash + someFile
Run Code Online (Sandbox Code Playgroud)

没有太大的区别,但可能更整洁?

axe*_*l_c 10

System.IO.Path.DirectorySeparatorChar是你想要的.

顺便说一句,更好的方法是使用System.IO.Path.Combine(somePath,someFile).

  • 如此多的赞成,甚至接受一个误导性的答案.Path.DirectorySeparatorChar返回"一个特定于平台的字符,用于分隔反映分层文件系统组织的路径字符串中的目录级别"(MSDN) - 因此在大多数.net情况下它不会是正斜杠.但是,如果您只是想知道如何以安全的方式连接目录路径和文件名,那么答案是正确的(尽管问题是错误的) (2认同)