.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
.Net的Collection类的一些使用说明

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

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




相关文章

相关软件