Collections in C # (Array/arraylist/list<t>/hashtable/dictionary)

Source: Internet
Author: User

Sweet Pony Pony Classmate's programming diary. Collections in C # (Array/arraylist/list<t>/hashtable/dictionary)

int [] numbers = new INT[5]; The length is 5 and the element type is int.
string[,] names = new string[5,4]; A two-dimensional array of 5*4
Byte[][] scores = new byte[5][]; An array of length 5, an array of byte elements, the length of an element array is unknown.

Different formats:
int[] numbers = new INT[5];
int[] numbers2 = new []{100, 200, 300, 400, 500};
Int[] Numbers3 = {100, 200, 300, 400, 500};

Names. GetLength (0); Get the transverse length of a two-dimensional array

Names. GetLength (1); Gets the longitudinal length of the two-dimensional array.

System.Collections.ArrayList

ArrayList al = new ArrayList ();

Al. ADD (5);

Al. ADD ("Hello Tom");

System.collections.generic.list<t>

list<int> intlist = new list<int> ();

Intlist.add (500);

Intlist.addrange (New int[]{1,100};

Intlist.insert (1, 1000);

CW (Intlist.contains (100));

CW (Intlist.indexof (10));

System.Collections.HashTable

HashTable ht = new HashTable ();

Ht. ADD ("name", "Tom");

Ht. ADD ("Age", 18);

System.collections.generic.dictionary<tkey, tvalue>

dictionary<string, string> dic = new dictionary<string, string> ();

Dic. ADD ("name", "Tom");

Dic. ADD ("Age", "eighteen");

Ha, actually, someone left a message.

Let's just say the difference.

1, the difference between array and the remaining four is "type specifies" "Fixed length", the remaining four lengths can be not fixed (also can specify length).

2, ArrayList and list<t> the difference is that list<t> is "type designation".

3, HashTable and Dictionary<tkey, the difference between tvalue> and 2 is the same. The latter is "type specified".

Category: C #

Collections in C # (Array/arraylist/list<t>/hashtable/dictionary)

Related Article

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.