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");
});
}
}
Do'stlaringiz bilan baham: |