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

Declaring Virtual Members

To illustrate the concept of virtual members from a different angle, let’s define another type hierarchy in which we declare virtual members ourselves (rather than overriding the ones from System.Object). A good example is the concept of a Shape that can be queried for its area and circumference. Depending on the subclass of Shape, calculation of those values will differ:

class Shape{    public virtual double Area    {        get { return 0.0; }    }    public virtual double Circumference    {        get { return 0.0; }    }}

For the time being, we use default implementations for those virtual property getters, which don’t look as if they produce very meaningful values. Later on, after you’ve ...

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