![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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:\
Advertisements