C#-এ সিস্টেমের সব ড্রাইভের নাম পেতে DriveInfo.GetDrives() স্ট্যাটিক মেথড ব্যবহার করা হয়। এটি System.IO নেমস্পেসে থাকে।
ব্যাখ্যা
var drives = DriveInfo.GetDrives();
এরপর লুপ চালিয়ে প্রতিটি ড্রাইভের নাম প্রিন্ট করা যায়:
foreach (DriveInfo d in drives) {
Console.WriteLine(d.Name);
}
উদাহরণ
using System;
using System.IO;
public class Demo {
public static void Main() {
var drives = DriveInfo.GetDrives();
foreach (DriveInfo d in drives) {
Console.WriteLine(d.Name);
}
}
}
আউটপুট (উইন্ডোজ)
C:\ D:\ E:\
আউটপুট (লিনাক্স)
/ /home /etc ...
নোট: আউটপুট অপারেটিং সিস্টেম অনুযায়ী ভিন্ন হবে।