Information Technology Reference
In-Depth Information
The set Accessor
When the indexer is the target of an assignment, the
set
accessor is called, and receives two
items of data, as follows:
An implicit parameter, named
value
, where
value
holds the data to be stored
One or more index parameters that represent where it should be stored
emp[0] = "Doe";
↑
↑
Index
Value
Parameter
Your code in the
set
accessor must examine the index parameters, determine where the
data should be stored, and then store it.
The syntax and meaning of the
set
accessor are shown in Figure 6-17. The left side of the
figure shows the actual syntax of the accessor declaration. The right side shows the semantics
of the accessor, if it were written using the syntax of a normal method. The figure on the right
shows that the
set
accessor has the following semantics:
t has a
void
return type.
It uses the same parameter list as that in the indexer declaration.
It has an implicit value parameter named
value
, of the same type as the indexer.
Figure 6-17.
The syntax and meaning of the set accessor declaration