What are Virtual Methods?

前端 未结 14 613
傲寒
傲寒 2020-11-29 03:02

Why would you declare a method as \"virtual\".

What is the benefit in using virtual?

14条回答
  •  猫巷女王i
    2020-11-29 03:36

    Needless to say, virtual methods come in handy when your code is trying to abide with the Open Closed Principle

    Read More about the Open Closed Principle here, Uncle Bob's original OCP whitepaper.

    Also pls be aware that methods are not virtual by default in C# unlike Java.

提交回复
热议问题