O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Virtual Members

Methods, properties, indexers, and events can be declared as virtual members using the virtual keyword used as a modifier on the member declaration. Virtual members can be overridden in a derived class to specialize their behavior. The simplest example can be found on the System.Object type itself, which is roughly defined as follows (omitting a bunch of irrelevant custom attributes and members):

public class Object{    public virtual bool Equals(object obj) { /* default implementation */ }    public virtual int GetHashCode() { /* default implementation */ }    public virtual string ToString() { /* default implementation */ }    public Type GetType() { /* the one and only implementation */ }    ... ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required