If we have list of files in our local folder and we want to delete the latest created file. The below code will do the same.
static void Main(string[] args)
{
//Pass the folder path where all files are existing
DirectoryInfo directInfo = new DirectoryInfo(@"C:\Kishor Kumar\Test");
FileInfo[] filelist = directInfo.GetFiles();
//make a list of all files using LINQ
var fileList = from n in filelist select new { FileName = n.FullName, CreationDate = n.CreationTime.ToLongDateString() };
//get the TOP FIRST file name using descending concept as the list is sorted by CreationDate
var fileLatest = (from m in fileList orderby m.CreationDate descending select m.FileName).First<string>();
Console.WriteLine(fileLatest );
//now delete the file
FileInfo file = new FileInfo(fileLatest );
file.Delete();
Console.WriteLine(fileLatest + " Deleted Successfully");
Console.Read();
}