public void SetWorkAddress(Address address) { if (Location == null) { Location = new Location(); } Location.Work = address; }
public void SetHomeAddress(Address address) { if (Location == null) { Location = new Location(); } Location.Home = address; }
public static void Main() { var asyncExample = new AsyncExceptionHandlerSample(); asyncExample.Run(); var student = new Student("John", "Smith", new DateTime(1990, 1, 1), new DateTime(2015, 1, 1)); WriteLine(student); WriteLine(student.Location?.Home?.ToString()); var address = new Address("9049 Main St", "Maple Grove", "MN", "55311", "Apt. 10"); student.SetHomeAddress(address); WriteLine("Address: "); WriteLine("----------------------------"); WriteLine(student.Location?.Home?.ToString()); WriteLine("----------------------------"); WriteLine(); WriteLine($"GPA (no transcript): {student.GPA:0.00}"); try { // student.Transcript = LoadTranscript(); student.Transcript = LoadTranscriptWithException(); WriteLine($"GPA: {student.GPA:0.00}"); } catch(Exception err) when(!Debugger.IsAttached) { WriteLine($"Error: {err.Message}"); WriteLine($"Stack Trace:\n{err.StackTrace}"); WriteLine("FAIL!"); } // Try to dispose student using null propagation operator (student as IDisposable)?.Dispose(); WriteLine("Dispose completed"); }