Console.WriteLine(Drives.GetAllDriveSizeA());
Console.WriteLine(Drives.GetAllDriveSizeB());
Console.WriteLine(Drives.GetAllDriveSizeC());
Console.WriteLine(Drives.GetAllDriveSizeD());
public static class Drives
public static long GetAllDriveSizeA()
return DriveInfo.GetDrives().Where(d => d.IsReady).Sum(d => d.TotalSize / 1024 / 1024 / 1024);
public static long GetAllDriveSizeB()
foreach (DriveInfo drive in DriveInfo.GetDrives())
total += drive.TotalSize / 1024 / 1024 / 1024;
public static long GetAllDriveSizeC()
var drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Length; i++)
total += drives[i].TotalSize / 1024 / 1024 / 1024;
public static long GetAllDriveSizeD()
DriveInfo.GetDrives().ToList().ForEach(drive =>
total += drive.TotalSize / 1024 / 1024 / 1024;