Пример #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();
        }
Пример #2
0
        public static void Teach(Mary child)
        {
            Action("teaches", child);

            child._iq += 20;

            Report(child, "iq");
        }
Пример #3
0
        public static void PlayWith(Mary child)
        {
            Action("plays with", child);

            child._happiness += 20;

            Report(child, "happiness");
        }
Пример #4
0
        // static methods
        public static void Feed(Mary child)
        {
            Action("feeds", child);

            child._fullness += 20;

            Report(child, "fullness");
        }
Пример #5
0
 // private helper methods.
 private static void Action(string action, Mary child) => Console.WriteLine($"Mary {action} {child._name}");