• <output id="aynwq"><form id="aynwq"><code id="aynwq"></code></form></output>

    <mark id="aynwq"><option id="aynwq"></option></mark>
  • <mark id="aynwq"><option id="aynwq"></option></mark><label id="aynwq"><dl id="aynwq"></dl></label>
  • 學習啦>學習英語>專業英語>計算機英語>

    c中arraylist的用法

    時間: 長思709 分享

      c中arraylist的用法的用法你知道嗎?下面小編就跟你們詳細介紹下c中arraylist的用法的用法,希望對你們有用。

      c中arraylist的用法的用法如下:

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

      一、優點

      1. 支持自動改變大小的功能

      2. 可以靈活的插入元素

      3. 可以靈活的刪除元素

      4. 可以靈活訪問元素

      二、局限性

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

      三、添加元素

      1.public virtual int Add(object value);

      將對象添加到ArrayList的結尾處

      ArrayList aList=new ArrayList();

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");

      內容為abcde

      2.public virtual void Insert(int index,object value);

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

      ArrayList aList=new ArrayList();

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");

      aList.Insert(0,"aa");

      結果為aaabcde

      3.public virtual void InsertRange(int index,ICollectionc);

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

      ArrayList aList=new ArrayList();

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");

      ArrayList list2=new ArrayList();

      list2.Add("tt");

      list2.Add("ttt");

      aList.InsertRange(2,list2);

      結果為abtttttcde

      四、刪除

      a)public virtual void Remove(object obj);

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

      ArrayList aList=new ArrayList();

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");

      aList.Remove("a");

      結果為bcde

      2.public virtual void RemoveAt(intindex);

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

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");

      aList.RemoveAt(0);

      結果為bcde

      3.public virtual void RemoveRange(int index,int count);

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

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");

      aList.RemoveRange(1,3);

      結果為ae

      4.public virtual void Clear();

      從ArrayList中移除所有元素。

      五、排序

      a)public virtual void Sort();

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

      ArrayListaList=newArrayList();

      aList.Add("e");

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      DropDownList1.DataSource=aList;//DropDown ListDropDownList1;

      DropDownList1.DataBind();

      結果為eabcd

      ArrayList aList=new ArrayList();

      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)public virtual void Reverse();

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

      ArrayList aList=new ArrayList();

      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)public virtual int IndexOf(object);

      b)public virtual int IndexOf(object,int);

      c)public virtual int IndexOf(object,int,int);

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

      ArrayList aList=new ArrayList();

      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)public virtual int LastIndexOf(object);

      e)public virtual int LastIndexOf(object,int);

      f)public virtual int LastIndexOf(object,int,int);

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

      ArrayList aList=new ArrayList();

      aList.Add("a");

      aList.Add("b");

      aList.Add("a");//同0

      aList.Add("d");

      aList.Add("e");

      intnIndex=aList.LastIndexOf("a");//值為2而不是0

      g)public virtual bool Contains(objectitem);

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

      七、獲取數組中的元素

      下面以整數為例,給出獲取某個元素的值的方法

      ArrayList aList=new ArrayList();

      for(int i=0;i<10;i++)

      aList.Add(i);

      for(i=0;i<10;i++)

      Textbox1.text+=(int)aList[i]+" ";//獲取的方式基本與一般的數組相同,使用下標的方式進行

      結果為:0 1 2 3 4 5 6 7 8 9

      八、其他

      1.public virtual intCapacity{get;set;}

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

      2.public virtual intCount{get;}

      獲取ArrayList中實際包含的元素數。

      Capacity是ArrayList可以存儲的元素數。Count是ArrayList中實際包含的元素數。Capacity總是大于或等于Count。如果在添加元素時,Count超過Capacity,則該列表的容量會通過自動重新分配內部數組加倍。

      如果Capacity的值顯式設置,則內部數組也需要重新分配以容納指定的容量。如果Capacity被顯式設置為0,則公共語言運行庫將其設置為默認容量。默認容量為16。

      在調用Clear后,Count為0,而此時Capacity切是默認容量16,而不是0

      3.public virtual void TrimToSize();

      將容量設置為ArrayList中元素的實際數量。

      如果不向列表中添加新元素,則此方法可用于最小化列表的內存系統開銷。

      若要完全清除列表中的所有元素,請在調用TrimToSize之前調用Clear方法。截去空ArrayList會將ArrayList的容量設置為默認容量,而不是零。

      ArrayList aList=new ArrayList();

      aList.Add("a");

      aList.Add("b");

      aList.Add("c");

      aList.Add("d");

      aList.Add("e");//Count=5,Capacity=16,

      aList.TrimToSize();//Count=Capacity=5;

    c中arraylist的用法

    c中arraylist的用法的用法你知道嗎?下面小編就跟你們詳細介紹下c中arraylist的用法的用法,希望對你們有用。 c中arraylist的用法的用法如下: System.Collections.ArrayList類是一個特殊的數組。通過添加和刪除元素,就可以動態改變數
    推薦度:
    點擊下載文檔文檔為doc格式
    537038 主站蜘蛛池模板: 国产卡一卡二卡3卡4卡无卡视频 | 特级黄色毛片在放| 国产精品第12页| 在线视频国产一区| 天天摸天天爽天天碰天天弄| 成人性生交大片免费看好| 日本a级作爱片金瓶双艳| 日韩内射美女片在线观看网站| 欧美一级片观看| 最近最好看2019年中文字幕| 欧美一区二区三区在线观看| 欧美性大战久久久久久片段| 97人人模人人爽人人少妇| 中文字幕人妻高清乱码| 中文字幕在线观看2020| 久久久www免费人成精品| 久久久综合视频| 中国国语毛片免费观看视频| 中文字幕成人网| 一二三四在线观看免费高清视频| 一本一本久久a久久综合精品蜜桃 一本一本久久a久久综合精品蜜桃 | 老师的兔子好多软水在线看| 精品视频在线观看你懂的一区 | 蜜桃臀av高潮无码| 色噜噜狠狠狠综合曰曰曰| 野外三级国产在线观看| 高清国产av一区二区三区| 草草草在线观看| 美女扒开裤子让男人桶视频| 欧美黑人疯狂性受xxxxx喷水| 扒丝袜永久网址pisiwa| 国产成人综合久久精品亚洲| 久久精品老司机| 欧美乱子伦xxxx| 亚洲欧洲精品成人久久曰影片 | 熟妇人妻无码XXX视频| 又大又硬又爽免费视频| 色大18成网站www在线观看 | 成人午夜视频在线观看| 久久婷婷五夜综合色频| 一级黄色大毛片|