首先对项目添加名为Microsoft.VisualBasic.dll的引用,然后添加命名空间
using Microsoft.VisualBasic.FileIO; usingSystem; namespaceleaver { classProgram { staticvoidMain(string[]args) { stringfilepath="leaver.txt"; FileSystem.DeleteFile(filepath,UIOption.OnlyErrorDialogs,RecycleOption.SendToRecycleBin); Console.WriteLine("删除文件完成"); } } }