Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
