C # Advanced (ix) C # data structure, collection

Source: Internet
Author: User

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 ());
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.