首页 IP地址查询 | Alexa排名查询 | 手机归属地查询
设为首页 收藏本站
  • 网络编程网络编程
  • 软件编程软件编程
  • 数据库技术数据库技术
  • 编程学院
  • 业界资讯 业界资讯
  • 源码中心源码中心
  • 会员中心会员中心
  • 页面导航: 首页C#编程变量 → ArrayList动态数组变量

    ArrayList动态数组变量

    发布:jeaye 发布日期:2009-01-15 字体:[增加 减小] 类型:原创

    在C#中用new 出来的数组是固定的,有时候我们就要用到动态数组,怎么办呢?

    不用怕,在C#中有一个ArrayList动态数组,可增加,删除,查询等。

    那么我简单的介绍一下它的功能和操作:

    在使用这个类时,大家要记住它的命名空间:"System.Collections"

    using System;
    using System.Collections;
    public class SamplesArrayList  
    {
    
       public static void Main()  
       {
    
          // 创建并添加数据
          ArrayList myAL = new ArrayList();
          myAL.Add("Hello");
          myAL.Add("World");
          myAL.Add("!");
    
          // Displays the properties and values of the ArrayList.
          Console.WriteLine( "myAL" );
          //获取数组中的个数
          Console.WriteLine( "    Count:    {0}", myAL.Count );
          //获取数组的空间大小(可包含的元素个数)
          Console.WriteLine( "    Capacity: {0}", myAL.Capacity );
          Console.Write( "    Values:" );
          PrintValues( myAL );
          myAL.Clear();     //清空数组
       }
    
       //循环读取数据
       public static void PrintValues( IEnumerable myList )  
       {
          foreach ( Object obj in myList )
             Console.Write( "   {0}", obj );
          Console.WriteLine();
       }
    
    }
    
    
    /* 
    This code produces output similar to the following:
    
    myAL
        Count:    3
        Capacity: f
        Values:   Hello   World   !
    
    */
    

    Tags: ArrayList 读取
    为配合网络严查,文章评论将关闭敬请谅解.
    同 类 文 章
    最 近 更 新
    热 点 排 行