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)