在Path
类中,有两个用于目录分隔符的字段,Path.DirectorySeparatorChar
和Path.AltDirectorySeparatorChar
。我知道它不是特定于 .NET 的,而是依赖于操作系统的,但我不明白为什么有两个这样的字符而不是一个。
例如只有一个Path.VolumeSeparatorChar
。
最佳答案
The value of this field is a backslash ('\') on UNIX, and a slash ('/') on Windows and Macintosh operating systems.
来自 MSDN system.io.path.altdirectoryseparatorchar
The value of this field is a colon (:) on Windows and Macintosh, and a slash (/) on UNIX operating systems. This is most useful for parsing paths such as "c:\windows" or "MacVolume:System Folder".
但是请注意,在 UNIX 上没有卷分隔符,因为设备是 mounted在挂载点的文件系统上,这是一个目录。因此,真正访问带有目录分隔符的文件,因此不会造成歧义。
关于c# - 为什么有两个目录分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50905209/