How to Get the List of All Drives installed in the System using C# ?

If you need to get the list of all drives installed on your system using C# , you can use the DriveInfo class which provides the static method GetDrives.

How to Get the List of All Drives installed in the System using C# ?

Below is a code snippet that iterates through all the drives and provides the necessary information about them.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
namespace GinktageConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
           var DrivesInPC = DriveInfo.GetDrives();
            foreach(var drive in DrivesInPC)
            {
                Console.WriteLine(drive.Name);
            }
           Console.ReadLine();
        }     
    }
    
}

1

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...