Harry Potter and the Sorcerer's Stone


Faylni asinxron tarzda o'chirish uchun C# dasturini yozing


Download 192.49 Kb.
bet62/62
Sana17.06.2023
Hajmi192.49 Kb.
#1535967
1   ...   54   55   56   57   58   59   60   61   62
Bog'liq
Algaritim amaliy-2

111. Faylni asinxron tarzda o'chirish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
string path = @"C:\Users\Username\Documents\FileToDelete.txt";
await DeleteFileAsync(path);
}

static async Task DeleteFileAsync(string path) {


await Task.Run(() => {
File.Delete(path);
Console.WriteLine("Fayl o'chirildi");
});
}
}
112. Fayl nomini asinxron tarzda o'zgartirish uchun C# dasturini yozing.
Javob:
using System;
using System.IO;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
string path = @"C:\Users\Username\Documents\OldName.txt";
string newPath = @"C:\Users\Username\Documents\NewName.txt";
await RenameFileAsync(path, newPath);
}

static async Task RenameFileAsync(string path, string newPath) {


await Task.Run(() => {
File.Move(path, newPath);
Console.WriteLine("Fayl nomi o'zgartirildi");
});
}
}
Download 192.49 Kb.

Do'stlaringiz bilan baham:
1   ...   54   55   56   57   58   59   60   61   62




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