欢迎光临
我们一直在努力

.Net的Collection类的一些使用说明-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

在没有今天的研究之前,我一直以为collection类里面只有arraylist和hashtable是有用的。今天早上大起看了书以后,对collection类有了更深的了解。其中以下的代码将是vb和c#穿插着讲。因为本人c#和vb都会,由于有些函数c#功能不是很好,所以使用了vb。

1:collection的当家花旦当然是数组咯。。数组的定义方法为:

int[] int_array=new int[10]

int[] myintarray = new int[5] { 1, 2, 3, 4, 5 };

上面两句话,我就不多做解释了。

2:结构体在数组中的使用,代码如下:

创建一个类:

class test

{

public string str_name;

public string str_phone;

}

对该类的引用和使用:

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我就不多说了,反正他最大的特点就是排序。

4:hashtable

hashtable的缺点就是不支持排序。很遗憾,另外在c#里根据key取value很麻烦。

5:sortedlist

sortedlist的使用方法和arraylist的使用方法差不多,只是sortedlist自动排序。

6:stack

dim st as new stack

st.push("aa")

st.push("bb")

stack是对仗,按照是先进后出的原则

7:queue

dim myque as new system.collections.queue

myque.enqueue("aa")

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 (ie.movenext)

str += ie.current

end while

c#:

system.collections.ienumerator ie=sl.keys.getenumerator();

string str="";

while(ie.movenext())

{

str+=ie.current.tostring();

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » .Net的Collection类的一些使用说明-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章