<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    備注學院

    LuLu

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      5 隨筆 :: 50 文章 :: 16 評論 :: 0 Trackbacks

    System.Collections.ArrayList類是一個特殊的數組。通過添加和刪除元素,就可以動態改變數組的長度。

    一.優點

    1。支持自動改變大小的功能
    2??梢造`活的插入元素
    3??梢造`活的刪除元素

    二.局限性

    跟一般的數組比起來,速度上差些

    三.添加元素

    1.publicvirtualintAdd(objectvalue);

    將對象添加到ArrayList的結尾處

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    內容為abcde

    2.publicvirtualvoidInsert(intindex,objectvalue);

    將元素插入ArrayList的指定索引處

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    aList.Insert(0,"aa");

    結果為aaabcde

    3.publicvirtualvoidInsertRange(intindex,ICollectionc);

    將集合中的某個元素插入ArrayList的指定索引處

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    ArrayListlist2=newArrayList();
    list2.Add("tt");
    list2.Add("ttt");
    aList.InsertRange(2,list2);

    結果為abtttttcde

    四.刪除

    a)publicvirtualvoidRemove(objectobj);

    從ArrayList中移除特定對象的第一個匹配項,注意是第一個

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    aList.Remove("a");

    結果為bcde

    2.publicvirtualvoidRemoveAt(intindex);

    移除ArrayList的指定索引處的元素

    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    aList.RemoveAt(0);

    結果為bcde

    3.publicvirtualvoidRemoveRange(intindex,intcount);

    從ArrayList中移除一定范圍的元素。Index表示索引,count表示從索引處開始的數目

    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    aList.RemoveRange(1,3);

    結果為ae

    4.publicvirtualvoidClear();

    從ArrayList中移除所有元素。

    五.排序

    a)publicvirtualvoidSort();

    對ArrayList或它的一部分中的元素進行排序。

    ArrayListaList=newArrayList();
    aList.Add("e");
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    DropDownList1.DataSource=aList;//DropDownListDropDownList1;
    DropDownList1.DataBind();

    結果為eabcd

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    aList.Sort();//排序
    DropDownList1.DataSource=aList;//DropDownListDropDownList1;
    DropDownList1.DataBind();

    結果為abcde

    b)publicvirtualvoidReverse();

    將ArrayList或它的一部分中元素的順序反轉。

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    aList.Reverse();//反轉
    DropDownList1.DataSource=aList;//DropDownListDropDownList1;
    DropDownList1.DataBind();
    結果為edcba

    六.查找

    a)publicvirtualintIndexOf(object);
    b)publicvirtualintIndexOf(object,int);
    c)publicvirtualintIndexOf(object,int,int);

    返回ArrayList或它的一部分中某個值的第一個匹配項的從零開始的索引。沒找到返回-1。

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");
    intnIndex=aList.IndexOf(“a”);//1
    nIndex=aList.IndexOf(“p”);//沒找到,-1
    d)publicvirtualintLastIndexOf(object);
    e)publicvirtualintLastIndexOf(object,int);
    f)publicvirtualintLastIndexOf(object,int,int);

    返回ArrayList或它的一部分中某個值的最后一個匹配項的從零開始的索引。

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("a");//同0
    aList.Add("d");
    aList.Add("e");
    intnIndex=aList.LastIndexOf("a");//值為2而不是0

    g)publicvirtualboolContains(objectitem);

    確定某個元素是否在ArrayList中。包含返回true,否則返回false

    七.其他

    1.publicvirtualintCapacity{get;set;}

    獲取或設置ArrayList可包含的元素數。

    2.publicvirtualintCount{get;}

    獲取ArrayList中實際包含的元素數。
    Capacity是ArrayList可以存儲的元素數。Count是ArrayList中實際包含的元素數。Capacity總是大于或等于Count。如果在添加元素時,Count超過Capacity,則該列表的容量會通過自動重新分配內部數組加倍。
    如果Capacity的值顯式設置,則內部數組也需要重新分配以容納指定的容量。如果Capacity被顯式設置為0,則公共語言運行庫將其設置為默認容量。默認容量為16。
    在調用Clear后,Count為0,而此時Capacity切是默認容量16,而不是0

    3.publicvirtualvoidTrimToSize();

    將容量設置為ArrayList中元素的實際數量。
    如果不向列表中添加新元素,則此方法可用于最小化列表的內存系統開銷。
    若要完全清除列表中的所有元素,請在調用TrimToSize之前調用Clear方法。截去空ArrayList會將ArrayList的容量設置為默認容量,而不是零。

    ArrayListaList=newArrayList();
    aList.Add("a");
    aList.Add("b");
    aList.Add("c");
    aList.Add("d");
    aList.Add("e");//Count=5,Capacity=16,
    aList.TrimToSize();//Count=Capacity=5;

    posted on 2008-08-07 10:03 smildlzj 閱讀(177) 評論(0)  編輯  收藏 所屬分類: C#
    主站蜘蛛池模板: 99热免费在线观看| 91精品成人免费国产| 韩国免费一级成人毛片| 亚洲男人天堂av| 久久香蕉国产线看免费| 久久亚洲国产成人亚| 伊人免费在线观看| 亚洲国产精品无码专区| a免费毛片在线播放| 久久久久久久综合日本亚洲| 国内永久免费crm系统z在线| 久久亚洲精品国产精品| 最新黄色免费网站| 亚洲xxxx视频| 国产一级高清视频免费看| 人人爽人人爽人人片A免费 | 亚洲午夜久久久影院伊人| 成人无码精品1区2区3区免费看| 亚洲精品国产品国语在线| 日韩免费无码一区二区三区| 久久国产精品亚洲综合| 日韩在线播放全免费| 亚洲日韩国产AV无码无码精品| 免费v片视频在线观看视频| 久久成人18免费网站 | 国产jizzjizz免费看jizz| 黄色网址免费在线| 国产精品国产亚洲精品看不卡| 日本人的色道免费网站| 久久无码av亚洲精品色午夜| 亚洲一区二区三区香蕉| 亚洲一级毛片免费看| 美女被吸屁股免费网站| 亚洲成a人片在线观看日本| 最近中文字幕免费mv视频8| 免费激情网站国产高清第一页| 久久精品国产99精品国产亚洲性色| 亚欧免费视频一区二区三区| 美景之屋4在线未删减免费| 亚洲人成在线播放网站岛国| 成人免费无码精品国产电影|