This program demonstrates the System.IO namespace and uses the DriveInfo class to retrieve information about the drives available on the system. It displays the drive name, drive type and, when a drive is ready, its volume label, file system, available free space, total free space and total size.
10 AM Class
9 AM Class
The source comments state that the System.IO namespace contains types that allow reading and writing to files and data streams, and types that provide basic file and directory support.
The source comments list the following classes: DriveInfo, Directory, DirectoryInfo, File, FileInfo, FileStream, StreamWriter, StreamReader, BinaryWriter and BinaryReader.
This program uses the DriveInfo class to work with drive information.
DriveInfo.GetDrives() is used in the program to retrieve the drives and store them in a DriveInfo array named drives.
The foreach loop processes each DriveInfo object from the drives array one by one.
drive.Name is used to display the name of the current drive.
drive.DriveType is used to display the type of the current drive.
The program checks drive.IsReady before accessing and displaying additional drive information.
When the drive is ready, drive.VolumeLabel is displayed.
When the drive is ready, drive.DriveFormat is displayed as the file system.
The program divides AvailableFreeSpace, TotalFreeSpace and TotalSize by 1024 three times to display the values in GB.
DriveInfo.GetDrives() retrieves the drives and stores them in the drives array.
The foreach loop processes each DriveInfo object in the drives array.
drive.Name is displayed for the current drive.
drive.DriveType is displayed for the current drive.
The if condition checks drive.IsReady before displaying additional information.
When the drive is ready, drive.VolumeLabel is displayed.
When the drive is ready, drive.DriveFormat is displayed.
drive.AvailableFreeSpace is divided by 1024 three times and displayed in GB.
drive.TotalFreeSpace is divided by 1024 three times and displayed in GB.
drive.TotalSize is divided by 1024 three times and displayed in GB.
The foreach loop continues until all drives in the drives array have been processed.
This program demonstrates how an application can enumerate available drives and display storage-related information such as drive name, type, file system and free or total space.
System.IO.
Types for reading and writing to files and data streams, and types that provide basic file and directory support.
DriveInfo.
By using DriveInfo.GetDrives().
A foreach loop.
drive.Name.
drive.DriveType.
It checks whether the drive is ready before displaying the additional drive information inside the if block.
drive.VolumeLabel.
drive.DriveFormat.
It divides the storage value by 1024, then 1024, then 1024.
1. Which namespace is used in this topic?
2. Which class is used to retrieve drive information?
3. Which method retrieves the drives?
4. Which loop is used to process each drive?
5. Which property displays the drive name?
6. Which property is checked before displaying detailed information?
7. Which property displays the volume label?
8. Which property is displayed as the file system?
9. Which value is used to display available free storage?
10. How many System.IO classes are listed in the source comments?
Write a C# program using DriveInfo.GetDrives() to retrieve the drives, process each drive using a foreach loop and display its name and drive type. When the drive is ready, display its volume label, file system, available free space, total free space and total size.
