get system total disk space in csharp

To get the total disk space of the system using C#, you can use the DriveInfo class. Here's an example:

main.cs
DriveInfo[] drives = DriveInfo.GetDrives();

foreach (DriveInfo drive in drives)
{
    if (drive.IsReady)
    {
        Console.WriteLine("Drive {0}", drive.Name);
        Console.WriteLine("  File type: {0}", drive.DriveType);
        Console.WriteLine("  Total size of drive: {0} bytes", drive.TotalSize);
    }
}
316 chars
12 lines

The DriveInfo.GetDrives() method returns an array of all drives in the system. The IsReady property checks if the drive is available. The TotalSize property returns the total size of the drive in bytes.

gistlibby LogSnag