Try-Catch-Finally c# in Console [closed]

Finally is used to have a guaranteed way of doing something, even if there is an exception thrown. In your case, you could for example dispose your stream, but generally it’s better to use using statement for objects that implement IDisposable, so you can just do

using (var stream = new FileStream(...))
{
   // do what ever, and the stream gets automatically disposed.
}

see:

using statement

IDisposable

Leave a Comment