The C # array concept has been thoroughly object-oriented, which has greatly reduced the difficulty of using our array structure, and it has been supported. NET platform's garbage collection mechanism. As the C # version continues to update, new data structures derived from the array are increasing. According to the 28 principle, we only need to use 20% of them to solve the 80% problem. But in order to achieve the ultimate, we still need to understand them. This article summarizes some of the array-related data structures and their usage until C # (4.0).
Basic array
string[] fruit = new String[5];
string[] vegetable = new string[] {"Chinese cabbage", "pepper", "potato", "tomato", "broccoli"};
Fruit[0] = "orange";
FRUIT[1] = "banana";
FRUIT[2] = "Apple";
FRUIT[3] = "Grape";
FRUIT[4] = "Lychee";
Multidimensional arrays
string[,] monthplan=new string[30,7];
Monthplan[0,0]= "A";
Monthplan[0, 1] = "B";
Jagged array
string[][] Foodenum = new string[7][];
Foodenum[0] = new STRING[10];
FOODENUM[1] = new string[9];
FOODENUM[2] = new String[8];
FOODENUM[3] = new String[7];
FOODENUM[4] = new String[6];
FOODENUM[5] = new STRING[5];
FOODENUM[6] = new STRING[6];
IEnumerator interface
public static ienumerator<string> Yield ()
{
Yield return "Apple";
Yield return "orange";
Yield return "banana";
}
public static void Ienumeratortest ()
{
var iterator=yield ();
while (iterator. MoveNext ())
{
Console.WriteLine (iterator). current);
}
/*out put
apple
orange
Banana
*/
}
Array Fragment
public static void ArraySegment ()
{
string[] vegetable = new string[] {"Chinese cabbage", "pepper", "potato", " Tomato "," broccoli "};
Count:get data begin the current index.
arraysegment<string> arraysegment = new arraysegment<string> (vegetable,2,2);
for (int i = Arraysegment.offset I <= arraysegment.offset + arraysegment.count; i++)
{
Console.WriteLine ( Arraysegment.array[i]);
}
* * out put
* potato
tomato
broccoli
* * *