当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .Net的Collection类的一些使用说明

ASP.NET
asp.net 数据库的连接和datatable类
代码实现打印功能(asp.net+javascript)
asp.net 读取xml文件里面的内容,绑定到dropdownlist中
asp.net 执行事务代码
asp.net 对中文汉字的加密与解密代码
asp.net 下载文件时输出文件内容
asp.net TextBox控件设置ReadOnly后,不能回传。
c# 执行事务函数代码
asp.net 面试 笔试题目[附答案]
asp.net利用google的api做翻译
asp.ne去除html的函数代码
C# 添加图片水印类实现代码
Silverlight融合ajax实现前后台数据交互
mssql 存储过程调用C#编写的DLL文件
asp.net 需要登陆的网站上下载网页源代码和文件
asp.net cookie的操作,写入、读取与操作
asp.net textarea换行函数代码
.NET发起web请求时维持Session
asp.net 身份验证(最简单篇)
asp.net 身份验证(分目录验证篇)

ASP.NET 中的 .Net的Collection类的一些使用说明


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 217 ::
收藏到网摘: n/a


在没有今天的研究之前,我一直以为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;i3: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(); }