Page 186 - CSharp/C#
P. 186
EvaluatesTo: True
Inner Finally
Catch
Outer Finally
View Demo
In the example above, if the method SomeOperation does not wish to "leak" the global state changes
to caller's when clauses, it should also contain a catch block to modify the state. For example:
private static void SomeOperation()
{
try
{
Flag = true;
throw new Exception("Boom");
}
catch
{
Flag = false;
throw;
}
finally
{
Flag = false;
Console.WriteLine("Inner Finally");
}
}
It is also common to see IDisposable helper classes leveraging the semantics of using blocks to
achieve the same goal, as IDisposable.Dispose will always be called before an exception called
within a using block starts bubbling up the stack.
Auto-property initializers
Introduction
Properties can be initialized with the = operator after the closing }. The Coordinate class below
shows the available options for initializing a property:
6.0
public class Coordinate
{
public int X { get; set; } = 34; // get or set auto-property with initializer
public int Y { get; } = 89; // read-only auto-property with initializer
}
Accessors With Different Visibility
https://riptutorial.com/ 132

