class, it would inherit from the Animal class, and all public properties and
methods of Animal would be available to instances of the Dog class.
Similarly, we could create a new class based on the Dog class. In programming
circles, this is called deriving a subclass from Dog. For instance, we might create
a class called AustralianShepherd, and one for my other dog, Amigo, called
Chihuahua, both of which would inherit the properties and methods of the Dog
base class, and define new classes specific to each breed.
Dont worry too much if this is still a little unclear. The best way to appreciate
inheritance is to see it used in a real program. The most obvious use of inheritance
in ASP.NET is in the technique called code-behind, and well build plenty of ex-
amples using inheritance and code-behind in Chapter 4.
Objects In .NET
If this is the first book in which youve read about object oriented programming,
youve probably started to dream about objects! Dont worry, the effect of first
exposure to objects doesnt usually last for more than a week. Even though this
is yet another discussion about objects, I promise it wont be boring. Moreover,
in the course of this section, well cover some important concepts that every ser-
ious .NET programmer must know.
So far, weve explored various concepts that apply in one form or the other to
almost any truly object oriented language. Every language has its peculiarities,
but the general concepts are the same in all of these languages.
You may already have heard the common mantra of object oriented programmers:
everything is an object. This has two meanings. First of all, in C#, every program
consists of a class. In all stages of application development, from design to imple-
mentation, decisions must be made in regard to the way we design and relate
objects and classes to each other. Yes, objects are everywhere.
.NET extends this to yet another level, giving the phrase everything is an object
extra meaning. In the world of .NET, every class ultimately derives from a base
class named Object, so everything is an object becomes everything is an Ob-
ject.
If you look at the documentation for the ASP.NET Page class, you can see the
list of classes from which this class inherits, as shown in Figure 3.7.
85
Objects In .NET
Figure 3.7. The Page classs documentation
Youll remember from the last section that we said our hypothetical
AustralianShepherd class would inherit from the more general Dog class, which,
in turn, would inherit from the even more general Animal class. This is exactly
the kind of relationship thats being shown in Figure 3.7Page inherits methods
and properties from the TemplateControl class, which in turn inherits from a
more general class called Control. In the same way that we say that an Australian
Shepherd is an Animal, we say that a Page is a Control. Control, like all .NET
classes, inherits from Object.
Since Object is so important that every other class derives from it, either directly
or indirectly, it deserves a closer look. Object contains the basic functionality
that the designers of .NET felt should be available in any object. The Object
class contains these public members:
Equals
ReferenceEquals
GetHashCode
GetType
86
Chapter 3: VB and C# Programming Basics

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.