54. C# yordamida kompyuterning mantiqiy drayverlarini oling.
Javob:
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
Console.WriteLine($"Drive {drive.Name} ({drive.DriveType}):");
Console.WriteLine($" Available space: {drive.AvailableFreeSpace} bytes");
Console.WriteLine($" Total space: {drive.TotalSize} bytes");
}
55. C# yordamida diskning mavjud bo'sh joyini oling.
Javob:
C# yordamida mavjud disk maydonini olish uchun siz System.IO nom maydonidagi DriveInfo sinfidan foydalanishingiz mumkin.
DriveInfo driveInfo = new DriveInfo("C"); // Replace "C" with the drive letter you want to check
long availableSpace = driveInfo.AvailableFreeSpace;
Console.WriteLine("Available space: {0} bytes", availableSpace);
56. C# yordamida diskning umumiy hajmini oling.
Javob:
C# yordamida diskning umumiy hajmini olish uchun siz bir xil DriveInfo sinfidan foydalanishingiz mumkin.
DriveInfo driveInfo = new DriveInfo("C"); // Replace "C" with the drive letter you want to check
long totalSize = driveInfo.TotalSize;
Console.WriteLine("Total disk size: {0} bytes", totalSize);
57. C# yordamida drayver formatini oling.
Javob:
using System.IO;
class Program
{
static void Main(string[] args)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
Console.WriteLine("Drive: " + drive.Name);
Console.WriteLine("Format: " + drive.DriveFormat);
}
}
}
58. C# yordamida diskning ovoz balandligi yorlig'ini oling.
Javob:
using System.Management;
public static bool IsDriveConnected(string driveLetter)
{
string query = "SELECT * FROM Win32_Volume WHERE DriveLetter = '" + driveLetter + ":'";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject drive in searcher.Get())
{
string driveType = drive["DriveType"].ToString();
if (driveType == "2" || driveType == "5")
{
return true; // Ses bağlantısı var
}
}
return false; // Ses bağlantısı yok
}
Do'stlaringiz bilan baham: |