First, the basic concept of the set
In. NET, the support for data structures is the combination of many similar objects. The simplest data structure is the array.
A collection represents a set of objects that can be accessed by traversing each element, especially if a foreach loop can be used to access them. An object is a collection if it can provide references to related objects. Called
Using a Foreach loop is the primary purpose of the collection, and the collection does not provide additional attributes.
Second, the list of arrays.
Array lists are similar to arrays, but array lists can be enlarged. After the specified size, the array can no longer be added, but the array list is available.
For example ArrayList arraylisttest=new arrarylist (10); The sentence creates a Arrarylist object of size 10, and when we add the 11th item to it, the capacity automatically expands 1 time times, and then it becomes 20, and the original object is added to the garbage collector's tag.
The way to add an object to it is. ADD ()
For example: Arraylisttest.add ("gosoa.com.cn");
Let's take a complete look at an example.
Using System;
Using System.Collections;
Namespace gosoa.com.cn
{
Class Test
{
static void Main ()
{
ArrayList arraytest = new ArrayList (4);
Arraytest.add ("www.");
Arraytest.add ("Gosoa.");
Arraytest.add ("com.");
Arraytest.add ("cn");
foreach (string item in Arraytest)
{
Console.Write (item);
}
Console.WriteLine ("\ n" +arraytest.capacity.tostring ());
Arraytest.add ("url");
Console.WriteLine (ArrayTest.Capacity.ToString ());
}
}
}