Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Daniel Solis - Illustrated C# 2010 - 2010.pdf
Скачиваний:
16
Добавлен:
11.06.2015
Размер:
11.23 Mб
Скачать

CHAPTER 4 CLASSES: THE BASICS

Overview of Classes

In the previous chapter, you saw that C# provides six user-defined types. The most important of these, and the one I’ll cover first, is the class. Since the topic of classes in C# is a large one, its discussion will be spread over the next several chapters.

A Class Is an Active Data Structure

Before the days of object-oriented analysis and design, programmers thought of a program as just a sequence of instructions. The focus at that time was on structuring and optimizing those instructions. With the advent of the object-oriented paradigm, the focus changed from optimizing instructions to organizing a program’s data and functions into encapsulated sets of logically related data items and functions, called classes.

A class is a data structure that can store data and execute code. It contains the following:

Data members, which store data associated with the class or an instance of the class. Data members generally model the attributes of the real-world object the class represents.

Function members, which execute code. Function members generally model the functions and actions of the real-world object the class represents.

A C# class can have any number of data and function members. The members can be any combination of nine possible member types. Table 4-1 shows these member types. The ones I’ll cover in this chapter—fields and methods—are checked in the table.

Table 4-1. Types of Class Members

Data Members Store Data

Function Members Execute Code

Fields

Methods

Operators

Constants

Properties

Indexers

 

Constructors

Events

Destructors

Note Classes are encapsulated sets of logically related data items and functions that generally represent objects in the real world or a conceptual world.

50

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]