// instance methods can use a static method, a static method cannot use an instance method private static void Report(Mary child, string state) { var stateValue = typeof(Mary).GetField($"_{state}").GetValue(child); Console.WriteLine($"{child._name}'s {state} is now {stateValue}"); Console.WriteLine(); }
public static void Teach(Mary child) { Action("teaches", child); child._iq += 20; Report(child, "iq"); }
public static void PlayWith(Mary child) { Action("plays with", child); child._happiness += 20; Report(child, "happiness"); }
// static methods public static void Feed(Mary child) { Action("feeds", child); child._fullness += 20; Report(child, "fullness"); }
// private helper methods. private static void Action(string action, Mary child) => Console.WriteLine($"Mary {action} {child._name}");