Indexers
· An indexer is a member that allows an object to be
indexed in the same way that an array can be indexed.
Differences between
Properties and Indexers
· All properties are identified by name, while indexers
are identified by their signature.
· Properties can be static members, while indexers are
always instance members.
· A get accessor of a property is equivalent to a method
with no parameters, while a get accessor of an indexer is equivalent to a
method with the same parameter list as the indexer.
· A set accessor of a property is equivalent to a method
with a single parameter named value,while a set accessor of an indexer is equivalent
to a method with the same formal parameter list as the indexer, with the
addition of a parameter named value.
Property
|
Indexer
|
Identified by its name.
|
Identified by its signature
|
Accessed through a simple name or a
member access.
|
Accessed through an element access.
|
Can be a static or an instance
member.
|
Must be an instance member.
|
A get accessor of a property
has no parameters.
|
A get accessor of an indexer
has the same formal parameter list as the indexer.
|
A set accessor of a property
contains the implicit value parameter.
|
A set accessor of an indexer
has the same formal parameter list as the indexer, in addition to the value
parameter.
|
No comments:
Post a Comment