C# Program to get the name of the drive

CsharpProgrammingServer Side Programming

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:/
raja
Published on 05-Sep-2018 10:47:47
Advertisements