C#子类访问基类成员

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            zzl z=new zzl();
            Console.WriteLine("zzl class a={0}",z.a());
            zzl2 z2=new zzl2();
            Console.WriteLine("zzl2 class a={0}",z2.a());
            Console.ReadKey();
        }
    }
    public class zzl
    {
        public  virtual int  a()
        {
            int a;
            int b;
            a = 1;
            b = 1;
            return a;
        }
    }
    public class zzl2:zzl
    {
        public  override int a()
        {
            int a;
            int b;
            a = 2;
            b = 2;
           return base.a();
        }
      
    }
}

结果为:

zzl class a=1

zzl2 class a=1

原文地址:https://www.cnblogs.com/lori/p/1687869.html