Skip to Main Content
Programming C#
book

Programming C#

by Jesse Liberty
July 2001
Intermediate to advanced content levelIntermediate to advanced
688 pages
16h 14m
English
O'Reilly Media, Inc.
Content preview from Programming C#

The Root of all Classes: Object

All C# classes, of any type, are treated as if they ultimately derive from System.Object. Interestingly, this includes value types!

A base class is the immediate “parent” of a derived class. A derived class can be the base to further derived classes, creating an inheritance “tree” or hierarchy. A root class is the topmost class in an inheritance hierarchy. In C#, the root class is Object. The nomenclature is a bit confusing until you imagine an upside-down tree, with the root on top and the derived classes below. Thus, the base class is considered to be “above” the derived class.

Object provides a number of methods that subclasses can and do override. These include Equals( ) to determine if two objects are the same, GetType( ), which returns the type of the object (discussed in Chapter 18), and ToString( ), which returns a string to represent the current object (discussed in Chapter 10). Table 5-1 summarizes the methods of Object.

Table 5-1. The methods of Object

Method

What It Does

Equals( )

Evaluates whether two objects are equivalent.

GetHashCode( )

Allows objects to provide their own hash function for use in collections (see Chapter 9).

GetType( )

Provides access to the type object (see Chapter 18).

ToString( )

Provides a string representation of the object.

Finalize( )

Cleans up nonmemory resources (see Chapter 4).

MemberwiseClone( )

Creates copies of the object; should never be implemented by your type.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming C#, Second Edition

Programming C#, Second Edition

Jesse Liberty
Programming C# 12

Programming C# 12

Ian Griffiths
Programming C# 8.0

Programming C# 8.0

Ian Griffiths

Publisher Resources

ISBN: 0596001177Supplemental ContentCatalog PageErrata