25.12.2015 Views

Professional

1l6xhbR

1l6xhbR

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Referencing a class through its interface . . . . . . . . . . . . . . . . . . . . . .280<br />

Working with multiple interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . .281<br />

Explicitly implementing an interface . . . . . . . . . . . . . . . . . . . . . . . . .282<br />

Interface restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .283<br />

Defining and using interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .284<br />

Abstract classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .293<br />

Abstract methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295<br />

Sealed classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295<br />

Sealed methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295<br />

Implementing and using an abstract class . . . . . . . . . . . . . . . . . . . .296<br />

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .302<br />

Quick reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .303<br />

Chapter 14 Using garbage collection and resource management 305<br />

The life and times of an object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305<br />

Writing destructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .306<br />

Why use the garbage collector? . . . . . . . . . . . . . . . . . . . . . . . . . . . . .308<br />

How does the garbage collector work? . . . . . . . . . . . . . . . . . . . . . . .310<br />

Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .310<br />

Resource management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .311<br />

Disposal methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .311<br />

Exception-safe disposal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .312<br />

The using statement and the IDisposable interface . . . . . . . . . . . . .312<br />

Calling the Dispose method from a destructor . . . . . . . . . . . . . . . . .314<br />

Implementing exception-safe disposal . . . . . . . . . . . . . . . . . . . . . . . . . . . . .316<br />

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .325<br />

Quick reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .325<br />

PART III DEFINING EXTENSIBLE TYPES WITH C#<br />

Chapter 15 Implementing properties to access fields 329<br />

Implementing encapsulation by using methods . . . . . . . . . . . . . . . . . . . . .329<br />

What are properties? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .331<br />

Contents xi

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!