gpt4 book ai didi

c# - Path.GetDirectoryName 在 UNC 路径上返回 null

转载 作者:行者123 更新时间:2023-11-30 12:27:11 25 4
gpt4 key购买 nike

Path.GetDirectoryName(@"C:\\");

返回 null 和

Path.GetDirectoryName(@"C:\\Foo");

返回 C:\

虽然这正是 documentation 中提到的行为我想知道为什么

Path.GetDirectoryName(@"\\server.domain.tld\Foo");

返回 null 而不是我预期的\server.domain.tld\

有人知道为什么吗?

最佳答案

通常,UNC 路径结构是 \\{server}\{share}\{path.....},所以你的 UNC 中的 "Foo" example 等效于第一个示例的 "C:\" 。这就是为什么您的 UNC 示例的路径得到 null 的原因。

"\\server\foo\bar" 的路径将是 "bar"

关于c# - Path.GetDirectoryName 在 UNC 路径上返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26211652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com