Computer >> Máy Tính >  >> Lập trình >> C#

GetLogicalDrives trong C #

Để lấy tất cả các ổ đĩa trên hệ thống, hãy sử dụng phương thức GetLogicalDrives () trong C # -

Environment.GetLogicalDrives()

Sử dụng nó với phương thức Join để nhận danh sách các ổ đĩa logic được phân tách bằng dấu phẩy -

string.Join(",", Environment.GetLogicalDrives())

Ví dụ

using System;
using System.IO;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         Console.WriteLine(string.Join(",", Environment.GetLogicalDrives()));
      }
   }
}

Đầu ra

/,/etc/resolv.conf,/etc/hostname,/etc/hosts,/run/secrets,/home/cg/root