Harry Potter and the Sorcerer's Stone


Faylga ma'lumotlarni asinxron tarzda yozish uchun C# dasturini yozing


Download 192.49 Kb.
bet55/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   51   52   53   54   55   56   57   58   ...   62
Bog'liq
Algaritim amaliy-2

84. Faylga ma'lumotlarni asinxron tarzda yozish uchun C# dasturini yozing.
Javob:
using System.IO;
string path = "data.txt";
using (StreamWriter sw = new StreamWriter(path, true))
{
sw.WriteLine("Hello, world!");
}
85. Katalogni o'chirish uchun C# dasturini yozing.
Javob
using System.IO;
Directory.Delete("myFolder", true);
86. Katalogni ko'chirish uchun C# dasturini yozing.
Javob:
using System.IO;
Directory.Move("myFolder", "newFolder");
87. Katalogdan nusxa olish uchun C# dasturini yozing.
Javob:
using System.IO;
string sourceDirName = "myFolder";
string destDirName = "backupFolder";
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
foreach (string fileName in Directory.GetFiles(sourceDirName))
{
string destFileName = Path.Combine(destDirName, Path.GetFileName(fileName));
File.Copy(fileName, destFileName, true);
}
88. Katalogdagi kataloglarni olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program {
static void Main(string[] args) {
DirectoryInfo directoryInfo = new DirectoryInfo("C:\\Users\\Username\\Documents");
DirectoryInfo[] directories = directoryInfo.GetDirectories();
foreach (DirectoryInfo dir in directories) {
Console.WriteLine(dir.Name);
}
}
}
89. Fayllarni katalogga olish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
class Program {
static void Main(string[] args) {
string sourceFile = "C:\\Users\\Username\\Downloads\\example.txt";
string destinationFolder = "C:\\Users\\Username\\Documents";
string fileName = Path.GetFileName(sourceFile);
string destinationPath = Path.Combine(destinationFolder, fileName);
File.Copy(sourceFile, destinationPath);
}
}

Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   51   52   53   54   55   56   57   58   ...   62




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