为什么GetDirectoryName返回null C:\? [英] Why does GetDirectoryName return null for C:\?

查看:201
本文介绍了为什么GetDirectoryName返回null C:\?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚碰到什么似乎像一个奇怪的设计选择:

I just came across what seems like a weird design choice:

System.IO.Path.GetDirectoryName(@"C:\folder\file.ext")

返回C:\文件夹

returns "C:\folder"

System.IO.Path.GetDirectoryName(@"C:\")

返回null。

returns null.

我能更好地理解它,如果第一个例子中返回的文件夹。

I could understand it better if the first example returned "folder".

任何想法的为什么是这样的话?什么做的的做的时候,你只是想获得的文件夹路径?

Any ideas why this is the case? And what do you do when you just want to get the folder path?

推荐答案

从的函数的文档

返回值类型:
一个   包含目录字符串   信息路径,或    空引用   (在Visual Basic中为Nothing),如果路径   表示根目录   

(加入由我强调)

Return Value Type:
A String containing directory information for path, or null reference (Nothing in Visual Basic) if path denotes a root directory

(emphasis added by me)

这篇关于为什么GetDirectoryName返回null C:\?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆