C# 项目来获取根目录的名称


使用RootDirectory属性来获取根目录的名称。

首先,使用DriveInfo为其想要获取根目录的驱动器设置,-

DriveInfo dInfo = new DriveInfo("C");

现在,RootDirectory给你结果,-

dInfo.RootDirectory

示例

以下为完整代码,-

using System;
using System.Linq;
using System.IO;
public class Demo {
   public static void Main() {
      DriveInfo dInfo = new DriveInfo("C");
      Console.WriteLine("Root Directory: "+dInfo.RootDirectory);
   }
}

输出

以下为输出,-

C:\

上次更新: 2020年6月22日

532 次浏览

启动您的职业

完成课程获取认证

开始
广告
© . All rights reserved.