public static void Print(object obj) { IPlant plant = obj as IPlant; if (plant as IPlant != null) { Console.WriteLine("---------------"); Console.WriteLine(plant.ToString()); } else { throw new InvalidPlantException("Невозможно привести объект " + obj.ToString() + " к типу Iplant"); //Console.WriteLine("---------------Print for " + obj.GetType() + "---------------"); //Console.WriteLine(obj.ToString()); } }
public static void Print(IPlant plant) { Console.WriteLine("---------------"); Console.WriteLine(plant.ToString()); }