C# - Keyword usage virtual+override vs. new

后端 未结 10 2198
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 06:06

What are differences between declaring a method in a base type \"virtual\" and then overriding it in a child type using the \"override\" keyword as

10条回答
  •  余生分开走
    2020-11-22 06:51

    • new keyword is for Hiding. - means you are hiding your method at runtime. Output will be based base class method.
    • override for overriding. - means you are invoking your derived class method with the reference of base class. Output will be based on derived class method.

提交回复
热议问题