六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

ArrayList-asp.net基礎(chǔ)筆記

[摘要]ArrayList System.Collections.ArrayList類是一個(gè)特殊的數(shù)組。通過添加和刪除元素,就可以動(dòng)態(tài)改變數(shù)組的長(zhǎng)度。一.優(yōu)點(diǎn)1。支持自動(dòng)改變大小的功能2。可以靈活的插入元素3。可以靈活的刪除元素二.局限性跟一般的數(shù)組比起來,速度上差些 三.添加元素 1. publi...
 

ArrayList

  System.Collections.ArrayList類是一個(gè)特殊的數(shù)組。通過添加和刪除元素,就可以動(dòng)態(tài)改變數(shù)組的長(zhǎng)度。

一.優(yōu)點(diǎn)

1。支持自動(dòng)改變大小的功能

2。可以靈活的插入元素

3。可以靈活的刪除元素

二.局限性

跟一般的數(shù)組比起來,速度上差些

 

三.添加元素

1.  public virtual int Add(object value);

將對(duì)象添加到 ArrayList 的結(jié)尾處

ArrayList aList = new ArrayList();

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

內(nèi)容為a b c d e

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");

結(jié)果為aa a b  c d e

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

   將集合中的某個(gè)元素插入 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);

結(jié)果為a b tt ttt c d e

四.刪除

a)       public virtual void Remove(object obj);

   ArrayList 中移除特定對(duì)象的第一個(gè)匹配項(xiàng),注意是第一個(gè)

ArrayList aList = new ArrayList();

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

aList.Remove("a");

結(jié)果為b c d e

2. public virtual void RemoveAt(int index);

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

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

aList.RemoveAt(0);

結(jié)果為b c d e

 

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

ArrayList 中移除一定范圍的元素。

Index表示索引,count表示從索引處開始的數(shù)目

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

aList.RemoveRange(1,3);

結(jié)果為a e

4.  public virtual void Clear();

ArrayList 中移除所有元素。

 

五.排序

a)       public virtual void Sort();

對(duì) ArrayList 或它的一部分中的元素進(jìn)行排序。

ArrayList aList = new ArrayList();

aList.Add("e");

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

DropDownList1.DataSource = aList;  // DropDownList DropDownList1;

DropDownList1.DataBind();

結(jié)果為e a b c d

ArrayList aList = new ArrayList();

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

aList.Sort();  //排序

DropDownList1.DataSource = aList;  // DropDownList DropDownList1;

DropDownList1.DataBind();

結(jié)果為a b c d e

b)       public virtual void Reverse();

ArrayList 或它的一部分中元素的順序反轉(zhuǎn)。

ArrayList aList = new ArrayList();

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

aList.Reverse();  //反轉(zhuǎn)

DropDownList1.DataSource = aList;  // DropDownList DropDownList1;

DropDownList1.DataBind();

結(jié)果為 e d c b a

六.查找

a)       public virtual int IndexOf(object);

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

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

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

ArrayList aList = new ArrayList();

aList.Add("a");

aList.Add("b");

aList.Add("c");

aList.Add("d");

aList.Add("e");

int nIndex = 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 或它的一部分中某個(gè)值的最后一個(gè)匹配項(xiàng)的從零開始的索引。

ArrayList aList = new ArrayList();

aList.Add("a"); 

aList.Add("b");

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

aList.Add("d");

aList.Add("e");

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

g)       public virtual bool Contains(object item);

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

七.其他

1.public virtual int Capacity {get; set;}

獲取或設(shè)置 ArrayList 可包含的元素?cái)?shù)。

2.public virtual int Count {get;}

獲取 ArrayList 中實(shí)際包含的元素?cái)?shù)。

Capacity 是 ArrayList 可以存儲(chǔ)的元素?cái)?shù)。Count 是 ArrayList 中實(shí)際包含的元素?cái)?shù)。Capacity 總是大于或等于 Count。如果在添加元素時(shí),Count 超過 Capacity,則該列表的容量會(huì)通過自動(dòng)重新分配內(nèi)部數(shù)組加倍。

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

在調(diào)用Clear后,Count為0,而此時(shí)Capacity切是默認(rèn)容量16,而不是0

 

3.public virtual void TrimToSize();

將容量設(shè)置為 ArrayList 中元素的實(shí)際數(shù)量。

如果不向列表中添加新元素,則此方法可用于最小化列表的內(nèi)存系統(tǒng)開銷。

若要完全清除列表中的所有元素,請(qǐng)?jiān)谡{(diào)用 TrimToSize 之前調(diào)用 Clear 方法。截去空 ArrayList 會(huì)將 ArrayList 的容量設(shè)置為默認(rèn)容量,而不是零。

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;





主站蜘蛛池模板: 中国国产一国产一级毛片视频 | 泰剧不期而爱第三季免费全集观看 | 日韩欧美亚洲综合一区二区 | 天堂网在线资源 | 香蕉成人啪国产精品视频综合网 | 婷婷狠狠五月天小说免费 | 天天影视色香欲综合影视大全 | 性xxxxx免费视频播放 | 日本视频在线 | 日韩首页| 三级理论手机在线观看视频 | 中文字幕日韩精品亚洲七区 | 日韩国产欧美在线观看 | 最近中文字幕无免费视频 | 特级生活片 | 又粗又大又爽又紧免费视频 | 青青操影院 | 色婷婷啪啪 | 三级国产| 四虎国产成人免费观看 | 青草香蕉视频 | 青青草视频在线免费观看 | 天天天操天天天干 | 亚洲 欧美 日韩中文字幕一区二区 | 日韩一区二区在线观看 | 色综合天天综久久久噜噜噜久久〔 | 亚洲女人毛片 | 亚洲国产精品久久久天堂麻豆 | 日韩美女免费线视频网址 | 日韩爱爱 | 最新高清无码专区 | 亚洲欧美婷婷 | 婷婷久久综合九色综合九七 | 在线激情 | 四虎影院紧急入口 | 天天操天天干天天操 | 青春草在线观看精品免费视频 | 亚洲综合中文网 | 天天摸天天干 | 日日噜噜夜夜狠狠扒开双腿 | 日本高清视频一区二区三区 |