1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using System; namespace test { class Program { static void Main(string[] args) { FireBird bird = new FireBird(); Type type = bird.GetType(); while (type != null) { Console.WriteLine($"type = {type}"); type = type.BaseType; } Console.ReadKey(); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System; namespace test { interface IFlyable { void Fly(); } abstract class Bird : IFlyable { string Name { get; set; } = "tori"; public abstract void Fly(); public abstract void Sing(); } class FireBird : Bird { public string Name { get; set; } = "hino-tori"; public override void Fly() { Console.WriteLine($"{Name} is flying."); } public void Fire(string msg) { Console.WriteLine($"{Name} is firing. {msg}"); } public override void Sing() { Console.WriteLine($"{Name} is singing."); } } } |