您的位置:首页 > Web前端 > React

Item 33: Use the new Modifier Only to React to Base Class Updates(Effective C#)

2011-02-22 21:43 686 查看
code 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace EffectiveCSharpItem33
7 {
8 class Base
9 {
public void MagicMethod()
{
Console.WriteLine("magic method from base.");
}
}

class Derived : Base
{
public new void MagicMethod()
{
Console.WriteLine("magic method from derived.");
}
}

class Program
{
static void Main(string[] args)
{
Derived d = new Derived();
d.MagicMethod();

Base b = d as Derived;
b.MagicMethod();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐