Esempio n. 1
0
        // 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();
        }
Esempio n. 2
0
        public static void Teach(Mary child)
        {
            Action("teaches", child);

            child._iq += 20;

            Report(child, "iq");
        }
Esempio n. 3
0
        public static void PlayWith(Mary child)
        {
            Action("plays with", child);

            child._happiness += 20;

            Report(child, "happiness");
        }
Esempio n. 4
0
        // static methods
        public static void Feed(Mary child)
        {
            Action("feeds", child);

            child._fullness += 20;

            Report(child, "fullness");
        }
Esempio n. 5
0
 // private helper methods.
 private static void Action(string action, Mary child) => Console.WriteLine($"Mary {action} {child._name}");