首页 > Windows开发 > 详细

c#隐藏和重写基类方法的区别

时间:2015-11-30 21:55:49      阅读:293      评论:0      收藏:0      [点我收藏+]

c#隐藏和重写基类方法的区别

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

namespace interfaceInfo
{
    public class animal
    {
        public void action()
        {
            Console.WriteLine("eat sleep fuck");
        }

        public virtual void show()
        {
            Console.WriteLine("show...");
        }
    }
    public class dog : animal
    {
        public new void action()
        {
            Console.WriteLine("new...");
        }

        public override void show()
        {
            Console.WriteLine("override");
        } 



    }
    class Program
    {
        static void Main(string[] args)
        {
            dog d = new dog();
            d.action();  //new...
            d.show();   //override

            Console.ReadLine();

            animal an = new dog();
            an.action();  //  eat sleep fuck
            an.show();    //  override

            Console.ReadLine();
           
        }
    }
}

 

c#隐藏和重写基类方法的区别

原文:http://www.cnblogs.com/mc67/p/5008370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!