Friday, January 25, 2019

Create a file - Kosher to use Dispose

Yes I know I can use a using statement and that is the typical way to handle file creation. However I just want to create an empty file on disk and do nothing with it in code. Is it consider good practice to just call the Dispose method? Example.

File.Create(System.IO.Path.Combine(@"c:\tmp\example.txt")).Dispose(); 

as oppose to

using (FileStream s = File.Create(@"c:\tmp\example.txt")) { /* do nothing */ } 
Create a file - Kosher to use Dispose Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team