Harry Potter and the Sorcerer's Stone


C# yordamida drayver turini oling


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

59. C# yordamida drayver turini oling.
Javob:
using System.Management;
public static List GetDriverTypes()
{
List driverTypes = new List();
string query = "SELECT * FROM Win32_SystemDriver";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject driver in searcher.Get())
{
string driverType = driver["Type"].ToString();
if (!driverTypes.Contains(driverType))
{
driverTypes.Add(driverType);
}
}
return driverTypes;
}
60. C# yordamida diskning ildiz katalogini oling.
Javob:
using System.IO;
public static long GetDriveTotalSize(string driveLetter)
{
DriveInfo drive = new DriveInfo(driveLetter);
long totalSize = drive.TotalSize;
return totalSize;
}
61. Fayldan ma'lumotlarni o'qish va uni konsolda ko'rsatish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string filePath = "test.txt";
if (File.Exists(filePath))
{
string[] lines = File.ReadAllLines(filePath);
foreach (string line in lines)
{
Console.WriteLine(line);
}
}
else
{
Console.WriteLine("Fayl topilmadi!");
}
}
}
62. Faylga ma'lumotlarni yozish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
string filePath = "test.txt";
string[] lines = {"Bu birinchi qator", "Bu ikkinchi qator", "Bu uchinchi qator"};
try
{
using (StreamWriter writer = new StreamWriter(filePath))
{
foreach (string line in lines)
{
writer.WriteLine(line);
}
}
Console.WriteLine("Ma'lumotlar faylga yozildi.");
}
catch (Exception ex)
{
Console.WriteLine("Xatolik yuz berdi: " + ex.Message);
}
}
}

Download 192.49 Kb.

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




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