. NET Collection class, some instructions for using the

Source: Internet
Author: User
In the absence of today's research, I always thought that the collection class only ArrayList and Hashtable is useful. After reading the book this morning, I have a deeper understanding of the collection class. The following code will be VB and C # interspersed with speaking. Because I C # and VB will, because some functions of C # function is not very good, so the use of VB.

The 1:collection of Hua Dan is certainly an array. The array is defined by the following methods:

Int[] Int_array=new int[10]

int[] Myintarray = new Int[5] {1, 2, 3, 4, 5};
The above two words, I do not have much to explain.

2: The structure is used in the array, the code is as follows:

Create a class:

Class Test
{
public string Str_name;
public string Str_phone;
}
References to and use of this class:

Test[] Mytest=new test[3];
for (int i=0;i<mytest. length;i++)
{
Mytest[i]=new test ();
}
Mytest[0].str_name= "Hello";
Mytest[1].str_name= "world!";
Mytest[0].str_phone= "Hahah";

3:arraylist

ArrayList I will not say more, anyway, his biggest feature is the sort.

4:hashtable

The disadvantage of Hashtable is that it does not support sorting. Unfortunately, also in C # based on key to fetch value is very troublesome.

5:sortedlist

The use of SortedList and ArrayList method is similar, just sortedlist automatic sorting.

6:stack

Dim St as New Stack
St. Push ("AA")
St. Push ("BB")

Stack is antithesis, according to the principle of advanced after

7:queue

Dim Myque as New System.Collections.Queue
Myque. Enqueue ("AA")

Queue in stack just the opposite, the queue is a FIFO principle to come.

8:specialized

Specialized below have a lot of strength, oneself go to use just OK.

9: Enumerate VB and C # Examples:

Vb:

Dim ie as System.Collections.IEnumerator = al. Keys.getenumerator
Dim str as String = ""
while (ie. MoveNext)
str + IE. Current
End While

C#:

System.Collections.IEnumerator IE=SL. Keys.getenumerator ();
String Str= "";
while (ie. MoveNext ())
{
Str+=ie. Current.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.