

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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
- What are the security risks of USB drives?
- Get all Constructors in Java
- Get all characters before space in MySQL?
- How to get all the Get-Process properties using PowerShell?
- Get all digits from a string in Java
- Get all results using WHERE clause in MySQL?
- Get all fields names in a MongoDB collection?
- How to get all the aliases in PowerShell?
- Shortest Path to Get All Keys in C++
- How to get all the collections from all the MongoDB databases?
- Get all methods of any object JavaScript
Advertisements