static void Main(string[] args) { WriteLine("Creating object myObj..."); MyClass myObj = new MyClass("My Object"); WriteLine("myObj created."); for (int i = -1; i <= 0; i++) { try { WriteLine($"\nAttempting to assign {i} to myObj.Val..."); myObj.Val = i; WriteLine($"Value {myObj.Val} assigned to myObj.Val."); } catch (Exception e) { WriteLine($"Exception {e.GetType().FullName} thrown."); WriteLine($"Exception {e.Message}\""); } } WriteLine("\nOutputtin myObj.ToString()..."); WriteLine(myObj.ToString()); WriteLine("myObj.ToString() Output."); WriteLine("\nmyDoubledIntProp = 5..."); WriteLine($"Getting myDoubledIntProp of 5 is {myObj.myDoubledIntProp}"); ReadKey(); }
public static string MyExtension(this MyClass str) { return(str.ToString()); }