C# Program to get the name of the drive


Set the drive for which you want to display the name −

DriveInfo info = new DriveInfo("C");

Now, to get the drive name, use the Name property −

info.Name

Here is the complete code with output −

Example

using System;
using System.Linq;
using System.IO;
public class Demo {
   public static void Main() {
      DriveInfo info = new DriveInfo("C");
      Console.WriteLine(“Drive: “+info.Name);
   }
}

Output

The following is the output −

D:/

Updated on: 22-Jun-2020

134 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements