Harry Potter and the Sorcerer's Stone


C# yordamida kompyuterning mantiqiy drayverlarini oling


Download 192.49 Kb.
bet49/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   45   46   47   48   49   50   51   52   ...   62
Bog'liq
Algaritim amaliy-2

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
}

Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   45   46   47   48   49   50   51   52   ...   62




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling