Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Last active August 17, 2020 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/2a0291a076c77e197d849eab7c049b1b to your computer and use it in GitHub Desktop.
Save atifaziz/2a0291a076c77e197d849eab7c049b1b to your computer and use it in GitHub Desktop.
FileOptions.DeleteOnCode test for my StackOverflow answer https://stackoverflow.com/a/63451070/6682
using System.IO;
var fileName = Path.GetRandomFileName();
Console.WriteLine($"File name: {fileName}");
Console.WriteLine($"Exists? {File.Exists(fileName)}");
using (var fs = File.Create(fileName, 4096, FileOptions.DeleteOnClose))
Console.WriteLine($"Exists? {File.Exists(fileName)}");
Console.WriteLine($"Exists? {File.Exists(fileName)}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment