
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Get all drives in C#
Firstly, use GetDrives to get the name of all the drives −
var drv = DriveInfo.GetDrives();
Loop through to get the name of all the drives on the system −
foreach (DriveInfo dInfo in drv) { Console.WriteLine(dInfo.Name); }
Let us see the complete code −
Example
using System; using System.Linq; using System.IO; public class Demo { public static void Main() { var drv = DriveInfo.GetDrives(); foreach (DriveInfo dInfo in drv) { Console.WriteLine(dInfo.Name); } } }
Output
/etc/resolv.conf /etc/hostname /etc/hosts /run/secrets /home/cg/root
Note: The result will vary on different Operating Systems. The above output is shown on Linux OS.
It will produce the following result on Windows OS:
C:\ D:\ E:\
- Related Articles
- How to get mapped drives using PowerShell?
- Difference between AC Drives and DC Drives
- Writebox a best google drives syncs
- Types of Electric Motors Used in Industrial Electric Drives
- Get all Constructors in Java
- What are the security risks of USB drives?
- How a holistic strategy drives profitable business growth?
- Get all characters before space in MySQL?
- Get all digits from a string in Java
- Get all results using WHERE clause in MySQL?
- How to get all the aliases in PowerShell?
- Get all fields names in a MongoDB collection?
- Shortest Path to Get All Keys in C++
- How to get all the Get-Process properties using PowerShell?
- Get all declared fields from a class in Java

Advertisements