1. role:
Classes and instances can be used like arrays, which are also called attributes with parameters.
2. Differentiation
(1) Comparison between indexer and array:
The index value of the indexer is not subject to type restrictions. The index value used to access the array must be an integer, and the index can be another type of index value.
The indexer can be overloaded. A class can have multiple indexers.
The indexer does not directly store data for a variable. The indexer has get and set accessors.
The indexer allows instances of classes and structures to be indexed in the same way as arrays. The indexer is similar to an attribute. The difference is that their accessors use parameters. It is called the property with parameters.
(2) Comparison between the indexer and attributes:
Description: The attribute is identified by name, and the indexer is identified by function signature.
The indexer can be overloaded. Properties cannot be overloaded.
The attribute can be static. The indexer belongs to an instance Member and cannot be declared as static.
3. Use
(1) Example 1
string str = "abc";char c = str[0];
(2) Example 2
Static void main (string [] ARGs) {indexclass = new indexclass (); indexclass [0] = "Wang Wu"; indexclass [1] = "Zhao Si ";} class indexclass () {private string [] Name = new string [10]; Public String This [int Index] {get {return name [Index];} set {name [Index] = value ;}}}