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: 2020-06-22T14:33:38+05:30

174 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements