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.

Using properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .333<br />

Read-only properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .334<br />

Write-only properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .334<br />

Property accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .335<br />

Understanding the property restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . .336<br />

Declaring interface properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .337<br />

Replacing methods with properties . . . . . . . . . . . . . . . . . . . . . . . . . .339<br />

Generating automatic properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .343<br />

Initializing objects by using properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . .345<br />

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .349<br />

Quick reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .350<br />

Chapter 16 Using indexers 353<br />

What is an indexer?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .353<br />

An example that doesn’t use indexers . . . . . . . . . . . . . . . . . . . . . . . .353<br />

The same example using indexers . . . . . . . . . . . . . . . . . . . . . . . . . . .355<br />

Understanding indexer accessors . . . . . . . . . . . . . . . . . . . . . . . . . . . .357<br />

Comparing indexers and arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .358<br />

Indexers in interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .360<br />

Using indexers in a Windows application . . . . . . . . . . . . . . . . . . . . . . . . . . .361<br />

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .367<br />

Quick reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .368<br />

Chapter 17 Introducing generics 369<br />

The problem with the object type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .369<br />

The generics solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .373<br />

Generics vs. generalized classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . .375<br />

Generics and constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .375<br />

Creating a generic class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .376<br />

The theory of binary trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .376<br />

Building a binary tree class by using generics . . . . . . . . . . . . . . . . .379<br />

Creating a generic method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .389<br />

xii<br />

Contents

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

Saved successfully!

Ooh no, something went wrong!