I. Structure and indexer (also known as including parameter attributes) Class classstruct
{
Struct mystruct
{
Public String [] strtest;
Public String This [int Index]
{
Get
{
Return strtest [Index];
}
Set
{
Strtest [Index] = value;
}
}
}
Public static void main ()
{
Mystruct MS = new mystruct ();
Ms. strtest = new string [2];
MS [0] = "AAAAA ";
The MS [1] = "bbbbb ";
Console. writeline ("the first is {0}, the second is {1}", MS [0], MS [1]);
}
}
// Suitable for processing a large amount of data, such as reading a record from a database and performing operations
1. Add the public keyword before the structure member declaration
2. structure members cannot be initialized when the structure is declared.
3. attributes in the structure cannot be passed as ref or out parameters because they do not allocate storage space.
4. The structure can implement interfaces.
Class can also have an index (including parameter attributes) public class classindex
{
Public Boolean this [int I]
{
Get {;}
Set {;}
}
}
// The access method is
Classindex CI = new classindex (5 );
CI [0]
CI [1]
CI [2]
CI [3]
CI [4]
CI [5]
// Define get and set to perform value and value assignment.
// 1.c# you cannot specify a name for the indexer.
Automatically specified as get_item set_item
// 2. system. runtime. compilerservices. indexernameattribute can specify the name of the indexer. However, name locating indexer is not supported in C #.
[System. runtime. compilerservices. indexername ("myname")]
Public Boolean this [int I]
{
// The index is named set_myname get_myname, instead of set_item get_item.
}
// System. String is an indexer with a changed name. Its name is Chars rather than item. In this way, we can obtain a single character in a string.