using System.IO; class Program { static void Main() { using (var tempDir = new TempDirectory()) { // Perform operations within the temporary directory } } }
using System.IO; class Program { static void Main() { var tempDir = new TempDirectory(); string filePath = Path.Combine(tempDir.Path, "example.txt"); File.WriteAllText(filePath, "Hello, World!"); // Perform operations with file here tempDir.Dispose(); // Deletes the temporary directory and all its contents } }In this code example, a temporary directory is created and a file named `example.txt` is written to it. After any operations with the file are completed, the temporary directory is deleted by calling the `Dispose()` method on the TempDirectory object. The TempDirectory class is part of the Nito.AsyncEx NuGet package library.