Delete File Using Delete method


using System.IO;
using System;

//Delete method of class File is used to delete a file.
class DeleteFile
{
    static void Main()
    {

        string fileloc = "D://MyFile.txt";
        if (File.Exists(fileloc))   // Checks for the existence of specified file 
        {
            File.Delete(fileloc);   // Deletes file
        }
        Console.WriteLine("File deleted successfully");
        Console.ReadLine();
    }
}

Output:
File deleted successfully