c# delete code example

Example 1: how to delete all files in a directory c#

System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");

foreach (FileInfo file in di.GetFiles())
{
    file.Delete(); 
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
    dir.Delete(true); 
}

Example 2: c# remove

//using System;
string myString = "Hello Grepper Developers";

//Removing all characters starting from a position
string newStr = myString.Remove(5);
	//Output: Hello

//Removes a specified number of characters after starting from a position
string newStr2 = myString.Remove(5, 8);
	//Output: Hello Developers