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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...