FROM ME TO YOU

oh my bizarre life !!

継承のサンプル

    // 継承
    // User -> AdminUser

    class User
    {
        public string name;

        public User(string name)
        {
            this.name = name;
        }

        public virtual void SayHi()
        {
            Console.WriteLine($"Hi!{name}");
        }
    }

    class AdminUser : User
    {
        public AdminUser(string name) : base(name)
        {

        }

        public void SayHello()
        {
            Console.WriteLine($"Hello!{name}");
        }

        public override void SayHi()
        {
            Console.WriteLine($"AdminHi!{name}");
        }
            
    }


    class Program
    {
        static void Main(string[] args)
        {
            var tom = new User("tom");
            Console.WriteLine(tom.name);   // tom
            tom.SayHi();
            var Bob = new AdminUser("Bob");
            Console.WriteLine(Bob.name);   // Bob
            Bob.SayHello();
            Bob.SayHi();
        }
    }