在没有今天的研究之前,我一直以为COLLECTION类里面只有arraylist和Hashtable是有用的。今天早上大起看了书以后,对Collection类有了更深的了解。其中以下的代码将是VB和C#穿插着讲。因为本人C#和VB都会,由于有些函数C#功能不是很好,所以使用了VB。
1:Collection的当家花旦当然是数组咯。。数组的定义方法为:
int int_array=new int
int myIntArray= new int;
上面两句话,我就不多做解释了。
2:结构体在数组中的使用,代码如下:
创建一个类:
class test
对该类的引用和使用:
test mytest=new test;
for
mytest[0].str_name="hello";
mytest.str_name="world!";
mytest[0].str_phone="hahah";
3:ArrayList
ArrayList我就不多说了,反正他最大的特点就是排序。
4:Hashtable
Hashtable的缺点就是不支持排序。很遗憾,另外在C#里根据KEY取VALUE很麻烦。
5:SortedList
SortedList的使用方法和ArrayList的使用方法差不多,只是SortedList自动排序。
6:Stack
DimstAsNewStack
st.Push
st.Push
Stack是对仗,按照是先进后出的原则
7:Queue
DimmyqueAsNewSystem.Collections.Queue
myque.Enqueue
Queue于Stack刚刚相反,Queue是先进先出的原则来的。
8:Specialized
Specialized下面有好多实力,自己去用一下就OK了。
9:枚举VB和C#示例:
VB:
Dim ie As System.Collections.IEnumerator=al.Keys.GetEnumerator
Dim str As String=""
While
str+=ie.Current
End While
C#:
System.Collections.IEnumeratorie=sl.Keys.GetEnumerator;
stringstr="";
while)
1:Collection的当家花旦当然是数组咯。。数组的定义方法为:
int int_array=new int
int myIntArray= new int;
上面两句话,我就不多做解释了。
2:结构体在数组中的使用,代码如下:
创建一个类:
class test
对该类的引用和使用:
test mytest=new test;
for
mytest[0].str_name="hello";
mytest.str_name="world!";
mytest[0].str_phone="hahah";
3:ArrayList
ArrayList我就不多说了,反正他最大的特点就是排序。
4:Hashtable
Hashtable的缺点就是不支持排序。很遗憾,另外在C#里根据KEY取VALUE很麻烦。
5:SortedList
SortedList的使用方法和ArrayList的使用方法差不多,只是SortedList自动排序。
6:Stack
DimstAsNewStack
st.Push
st.Push
Stack是对仗,按照是先进后出的原则
7:Queue
DimmyqueAsNewSystem.Collections.Queue
myque.Enqueue
Queue于Stack刚刚相反,Queue是先进先出的原则来的。
8:Specialized
Specialized下面有好多实力,自己去用一下就OK了。
9:枚举VB和C#示例:
VB:
Dim ie As System.Collections.IEnumerator=al.Keys.GetEnumerator
Dim str As String=""
While
str+=ie.Current
End While
C#:
System.Collections.IEnumeratorie=sl.Keys.GetEnumerator;
stringstr="";
while)