December 2018
Beginner to intermediate
668 pages
15h 30m
English
If you don't need to catch any exceptions, then you can simplify the code that needs to check for a non-null object and then call its Dispose method by using the using statement.
The compiler changes your code into a full try and finally statement, but without a catch statement. You can use nested try statements; so, if you do want to catch any exceptions, you can, as shown in the following code example:
using (FileStream file2 = File.OpenWrite(Path.Combine(path, "file2.txt"))) { using (StreamWriter writer2 = new StreamWriter(file2)) { try { writer2.WriteLine("Welcome, ...Read now
Unlock full access