博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 关键字 virtual、override和new的用法
阅读量:4677 次
发布时间:2019-06-09

本文共 627 字,大约阅读时间需要 2 分钟。

代码如下:

class A{    public void foo()    {        Console.WriteLine("A::foo()");    }    public virtual void bar()    {        Console.WriteLine("A::bar()");    }}class B : A{    public new void foo()    {        Console.WriteLine("B::foo()");    }    public override void bar()    {        Console.WriteLine("B::bar()");    }}class Program{    static int Main(string[] args)    {        B b = new B();        A a = b;        a.foo(); // Prints A::foo        b.foo(); // Prints B::foo        a.bar(); // Prints B::bar        b.bar(); // Prints B::bar        return 0;    }}

 

转载于:https://www.cnblogs.com/dayang12525/p/11132993.html

你可能感兴趣的文章
为什么需要Docker?
查看>>
国内5家云服务厂商 HTTPS 安全性测试横向对比
查看>>
how to control project
查看>>
转 python新手容易犯的6个错误
查看>>
第四节 -- 列表
查看>>
Python入门学习笔记4:他人的博客及他人的学习思路
查看>>
webstorm里直接调用命令行
查看>>
关联规则算法之FP growth算法
查看>>
对数组序列进行洗牌
查看>>
决策树
查看>>
团队作业
查看>>
如何避免在简单业务逻辑上面的细节上面出错
查看>>
win7,Ubuntu 12.04 双系统修改启动项顺序三方法
查看>>
python--列表推导式和生成表达式
查看>>
P - Psychos in a Line 单调队列
查看>>
POJ 2653 Pick-up sticks(计算几何)
查看>>
大型网站高并发的架构演变图-摘自网络
查看>>
8丶运行及总结
查看>>
Unity获取手机的电量时间
查看>>
Spring框架:Spring容器具体解释
查看>>