private void BeHappy(object item) { IEmotional emotional = item as IEmotional; // conditional down casting if (emotional != null) { Console.Write($"{item.GetType().Name}: "); emotional.BeHappy(); } }
private void BeHappy(object obj) { IEmotional emotional = obj as IEmotional; if (emotional != null) { Console.WriteLine("{0}", obj.GetType().Name); emotional.BeHappy(); } }