section iV
Classes
The lessons in Section III focus on C# programming statements. They explain how to make
decisions with
if and switch statements, repeat program steps with loops, reuse code with
methods, and catch exceptions.
Methods are particularly useful for programming at a higher level because they let you
encapsulate complex behaviors in a tightly wrapped package. For example, you might write
a
CalculateGrade method that determines a student’s grades. This method can hide all of
the details of how grades are calculated. (Are tests graded on a curve? Is the grade a weighted
average of tests and homework assignments? How much is attendance worth?) The main pro-
gram only needs to know how to call the method, not how it works.
Classes provide another even more powerful method for abstracting complex entities into
manageable packages. For example, a
Student class might embody the idea of a student and
include basic information (name, address, phone), the courses that the student is taking, grades
(test scores, homework grades), and even attendance. It would also include methods such as
CalculateGrade for manipulating the Student data.
The lessons in this section explain classes. They explain how you can build classes, make one
class inherit the capabilities of another, and make a class override the features of its parent class.
LESSON 23: Defining Classes
LESSON 24: Initializing Objects
LESSON 25: Fine-Tuning Classes
LESSON 26: Overloading Operators
LESSON 27: Using Interfaces
LESSON 28: Making Generic Classes
596906c23.indd 267 4/7/10 12:33:42 PM
596906c23.indd 268 4/7/10 12:33:42 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181