Chapter 9

Defining Classes


  • How to define classes and interfaces in C#
  • How to use the keywords that control accessibility and inheritance
  • What the System.Object class is and its role in class definitions
  • How to use some helpful tools provided by Visual Studio (VS)
  • How to define class libraries
  • The differences and similarities between interfaces and abstract classes
  • More about struct types
  • Some important information about copying objects


You can find the code downloads for this chapter at on the Download Code tab. The code is in the Chapter 9 download and individually named according to the names throughout the chapter.

In Chapter 8, you looked at the features of object-oriented programming (OOP). In this chapter, you put theory into practice and define classes in C#. You won’t go so far as to define class members in this chapter, but you will concentrate on the class definitions themselves. That might sound a little limiting, but don’t worry — there’s plenty here to sink your teeth into!

To begin, you explore the basic class definition syntax, the keywords you can use to determine class accessibility and more, and the way in which you can specify inheritance. You also look at interface definitions because they are similar to class definitions in many ways.

The rest of the chapter covers various related topics that apply when defining classes in C#. ...

Get Beginning Visual C# 2012 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.