c#为什么当路径为"C:"时directoryInfo带我到应用程序文件夹? [英] c# why when the path is "C:" the directoryInfo takes me to the application folder?

查看:102
本文介绍了c#为什么当路径为"C:"时directoryInfo带我到应用程序文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当我输入路径"c:"时,它直接将我更改为应用程序文件夹?

Why when i give the path "c:" it changed me directly to application folder?

    static void Main(string[] args)
    {
        DirectoryInfo dir = new DirectoryInfo("c:");
        Console.WriteLine(dir.FullName);
        Console.ReadLine();
    }

输出如下:

c:\ users ... \ documents \ visual studio 2010 \ projects \ consoleApplication9 \ bin \ debug

c:\users...\documents\visual studio 2010\projects\consoleApplication9\bin\debug

但是当我给出@"c:\"时,它将进入磁盘c: 尽管"d:"@"d:\"占用了磁盘d:.

But when I give @"c:\" it goes to disk c: despite that "d:" and @"d:\" takes to disk d:.

所以我需要一种让"c:"进入磁盘c:

So I need a way to let "c:" takes to disk c:

提前谢谢!

推荐答案

static void Main(string[] args) 
    { 
        string YourDir = "c:";

        if (!YourDir.Substring(YourDir.Length - 1, 1).Equals(@"\"))
            YourDir += @"\";
        DirectoryInfo dir = new DirectoryInfo(YourDir); 
        Console.WriteLine(dir.FullName); 
        Console.ReadLine(); 
    } 

这篇关于c#为什么当路径为"C:"时directoryInfo带我到应用程序文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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