logo
CSharp_Prog_Guide

Надежное программирование

Существуют два основных способа повышения надежности и безопасности индексаторов.

Indexers in Interfaces

Indexers can be declared on an interface. Accessors of interface indexers differ from the accessors of class indexers in the following ways:

Thus, the purpose of the accessor is to indicate whether the indexer is read-write, read-only, or write-only.

The following is an example of an interface indexer accessor:

public interface ISomeInterface

{

//...

// Indexer declaration:

string this[int index]

{

get;

set;

}

}

The signature of an indexer must differ from the signatures of all other indexers declared in the same interface.