#349 – The Difference Between Virtual and Non-Virtual Methods

In C#, virtual methods support polymorphism, by using a combination of the virtual and override keywords.  With the virtual keyword on the base class method and the override keyword on the method in the derived class, both methods are said to be virtual.

Methods that don’t have either the virtual or override keywords, or that have the new keyword, are said to be non-virtual.

When a virtual method is invoked on an object, the run-time type of the object is used to determine which implementation of the method to use.

When a non-virtual method is invoked on an object, the compile-time type of the object is used to determine which implementation of the method to use.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #349 – The Difference Between Virtual and Non-Virtual Methods

  1. Pingback: #671 – A Base Class Constructor Can Call a Virtual Method « 2,000 Things You Should Know About C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: