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

Inheritance for Classes

The first thing we want to look at is how to derive a class from another one. C# uses a single syntax for inheritance both from a class or a set of interfaces, which is different from languages like Java, in which two keywords, extends and implements, are used. In the following example, we explicitly derive a class from System.Object:

class Person : Object{    public Person(string name, int age)    {        Name = name;        Age = age;    }    public string Name { get; private set; }    public int Age { get; private set; }}

The preceding code is no different from omitting the colon and base type altogether because Object is the default base type if left unspecified:

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