Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# 2008 Step by Step.pdf
Скачиваний:
24
Добавлен:
25.03.2016
Размер:
13.96 Mб
Скачать

308Part III Creating Components

5.Type a phone number for a different contact in the Phone Number text box, and then click Search by Phone.

The contact name is retrieved from the phone book and is displayed in the Name text box.

6.Type a name that you did not enter in the phone book into the Name text box, and then click Search by Name.

This time the Phone Number text box is empty, indicating that the name could not be found in the phone book.

7.Close the form, and return to Visual Studio 2008.

If you want to continue to the next chapter:

Keep Visual Studio 2008 running, and turn to Chapter 17. If you want to exit Visual Studio 2008 now:

On the File menu, click Exit. If you see a Save dialog box, click Yes (if you are using Visual Studio 2008) or Save (if you are using Visual C# 2008 Express Edition) and save the project.

Chapter 16 Quick Reference

To

Do this

Create an indexer for a class

Declare the type of the indexer, followed by the keyword this

or structure

and then the indexer arguments in square brackets. The body of

 

the indexer can contain a get and/or set accessor. For

 

example:

 

struct RawInt

 

{

...

public bool this [ int index ]

{

}

get { ...

set { ...

}

}

 

...

 

}

 

Define an indexer in an interface

Define an indexer with the get and/or set keywords. For example:

interface IRawInt

{

bool this [ int index ] { get; set; }

}

Implement an interface indexer in a class or structure

Implement an interface indexer by using explicit interface implementation in a class or structure

Chapter 16 Using Indexers

309

In the class or structure that implements the interface, define the indexer and implement the accessors. For example:

struct RawInt : IRawInt

{

...

public bool this [ int index ]

{

get { ... } set { ... }

}

...

}

In the class or structure that implements the interface, explicitly name the interface, but do not specify the indexer accessibility. For example:

struct RawInt : IRawInt

{

...

bool IRawInt.this [ int index ]

{

get { ... } set { ... }

}

...

}

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