惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
量子位
aimingoo的专栏
aimingoo的专栏
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
I
InfoQ
Jina AI
Jina AI
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
F
Full Disclosure
Vercel News
Vercel News
T
Tailwind CSS Blog
P
Proofpoint News Feed
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
D
Docker
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tenable Blog
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
D
DataBreaches.Net
The Hacker News
The Hacker News
J
Java Code Geeks
Hacker News: Ask HN
Hacker News: Ask HN
G
GRAHAM CLULEY
PCI Perspectives
PCI Perspectives
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
Forbes - Security
Forbes - Security
Microsoft Security Blog
Microsoft Security Blog
C
Check Point Blog
F
Fortinet All Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Latest news
Latest news
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Webroot Blog
Webroot Blog
L
LINUX DO - 最新话题
S
Secure Thoughts
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed

博客园 - kings

项目团队成长日志--聆听客户声音,沟通无所不在 TOAD使用筆記 使电脑鼠标右键相应快的办法 非常好用的对日面试资料(转) IT技術者日本語面接(ぎじゅつしゃにほんごめんせつ)によく出(で)る100質問(しつもん) 获取应用程序路径 再议 构造方法(转自Q.yuhen) 基元类型、值类型和引用类型(转自Q.yuhen) C# 2.0 - 泛型(Generics)(转自Q.yuhen) new 和 override 的区别(转自Q.yuhen) C# 方法参数 ref 详述(转自Q.yuhen) 浅析Family Show 2.0的动态换肤实现(转tonyqus) 浅析Family Show 2.0的子窗体实现(转tonyqus) webservice 遇到的小问题 泛型集合类型,赋予集合业务意义,增强集合的抽象使用(转-lizhe1985) WPF_Markup的几种写法 When I tab into a toolbar in WPF I can't tab out again? What can I do to change this tab behaviour? Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定之二:使用外部URL的XML文件)(转-大可山) Windows Presentation Foundation(WPF)中的数据绑定(使用XmlDataProvider作控件绑定)(转-大可山)
“多态”一个需要注意的问题(转自Q.yuhen)
kings · 2007-09-23 · via 博客园 - kings

在C#中只有属性和方法能被声明为virtual,而字段则不能。因此注意下面例子中的问题。

  public class Base
  {
    public int i = 10;

    public virtual void Test()
    {
      Console.WriteLine(i);
    }
  }

  public class Deliver : Base
  {
    public int i = 20;

    public override void Test()
    {
      Console.WriteLine(i);
    }
  }

  public class Class1
  {
    public static void Main(string[] args)
    {
      Deliver d = new Deliver();
      Base b = d;

      d.Test(); // 20
      b.Test(); // 20

      Console.WriteLine(b.i); // 10 问题就出在这,字段i并不支持多态。
    }
  }