5), C # _ indexer

Index is a set of get and set accessor, with similar properties.
----------------------------------- -------------------------------------------------- -----------
index and the property
index and the property is in many ways similar.
1). and attributes, indexers do not allocate memory to store.
2). indexers and properties are mainly be used to access other data members that are associated with these members, and to provide access to get and set them.
property generally is individual data members.
indexer generally represents a plurality of data members.
Description:
may be considered a class indexer the more data members provide get and set attributes. by providing an index, you can choose from a number of possible data members. index itself may be of any type, not just numeric types.
About indexer, there are some precautions follows
and property, the index may have only one access device can also be both.
indexer is always an instance member. and therefore can not be declared as static.
as with property, to achieve the get and set accessor code do not have to associate to a field or property. this code can do anything Things or do nothing, as long as the get accessor returns a specified type of value.
----------------------------- -------------------------------------------------- ----------------
statement indexer
declaration indexer syntax. Please note the following.
1). indexer has no name. the name is a key position in this.
2) Parameter List intermediate brackets.
3). Argument list must be declared at least one parameter.
Declaration statement is similar to the index property.
-------------------- -------------------------------------------------- -------------------------
indexer set accessor
when the index is used to assign, set accessor is called, and accepted two data, as follows:
an implicit parameter named value, value holds data to be saved;
one or more index parameter that indicates where the data should be saved.
code set accessor must check the index parameters to determine the data where to be stored, and save it.
SET accessor has the following semantics
return type of void.
the same argument list and it is declared indexer used in.
it has a name of a hidden parameter value, the reference value the same type and index type.
-------------------------------------------- --------------------------------------------------
indexer get accessor
when using the index value is acquired, you can call the get accessed by the one or more parameters which indicate the index parameter value acquisition.
get accessor vivo Code must check the index parameter is determined which indicates which field, and returns the value of the field.
-------------------------------------------------- --------------------------------------------
About indexer supplement
and Like property, you can not explicitly call the get and set accessor. Instead, when the index value Used in the expression, will automatically call the get accessor. when an assignment is an assignment to the index will automatically call set accessor.
in the "call" indexer, we supply parameters in the middle of the square brackets.
---------------------------------- -------------------------------------------------- ---------
overloading of indexers
as long as the parameter list indexer different classes can have any number of indexers. different index types is not enough. this is called overloading of indexers, so all indexes the device has the same "name": this access reference.

Guess you like

Origin www.cnblogs.com/linchenjian/p/11430559.html