最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#中ArrayList的使用方法

 更新時間:2013年12月09日 15:42:48   作者:  
這篇文章主要介紹了
System.Collections.ArrayList類是一個特殊的數(shù)組。通過添加和刪除元素,就可以動態(tài)改變數(shù)組的長度。

一.優(yōu)點

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

二.局限性

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

三.添加元素

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表示從索引處開始的數(shù)目
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可包含的元素數(shù)。
2.publicvirtualintCount{get;}
獲取ArrayList中實際包含的元素數(shù)。
Capacity是ArrayList可以存儲的元素數(shù)。Count是ArrayList中實際包含的元素數(shù)。Capacity總是大于或等于Count。如果在添加元素時,Count超過Capacity,則該列表的容量會通過自動重新分配內部數(shù)組加倍。
如果Capacity的值顯式設置,則內部數(shù)組也需要重新分配以容納指定的容量。如果Capacity被顯式設置為0,則公共語言運行庫將其設置為默認容量。默認容量為16。
在調用Clear后,Count為0,而此時Capacity切是默認容量16,而不是0
3.publicvirtualvoidTrimToSize();
將容量設置為ArrayList中元素的實際數(shù)量。
如果不向列表中添加新元素,則此方法可用于最小化列表的內存系統(tǒng)開銷。
若要完全清除列表中的所有元素,請在調用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; 

相關文章

  • Unity3D生成一段隧道網(wǎng)格的方法

    Unity3D生成一段隧道網(wǎng)格的方法

    這篇文章主要為大家詳細介紹了Unity3D生成一段隧道網(wǎng)格的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-08-08
  • C#的十種語法糖介紹

    C#的十種語法糖介紹

    這篇文章介紹了C#的十種語法糖,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • 如何在C#9 中使用static匿名函數(shù)

    如何在C#9 中使用static匿名函數(shù)

    這篇文章主要介紹了如何在C#9中使用static匿名函數(shù),幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下
    2021-03-03
  • 3種C# 加載Word的方法

    3種C# 加載Word的方法

    本次經驗內容分享通過C#程序來加載Word文檔的3種不同方法。分別是:加載本地Word文檔、以只讀模式加載Word文檔、從流加載Word 想具體了解的小伙伴請參考下文
    2021-09-09
  • C# Dictionary的使用實例代碼

    C# Dictionary的使用實例代碼

    C# Dictionary的使用實例代碼,需要的朋友可以參考一下
    2013-04-04
  • C#運算符重載用法實例分析

    C#運算符重載用法實例分析

    這篇文章主要介紹了C#運算符重載用法,實例分析了C#中運算符重載的基本實現(xiàn)與使用技巧,需要的朋友可以參考下
    2015-07-07
  • WPF自定義實現(xiàn)雷達圖控件的示例詳解

    WPF自定義實現(xiàn)雷達圖控件的示例詳解

    雷達圖用于表示不同內容的占比關系,在項目中有廣泛的應用,但是目前未曾有封裝良好的雷達圖控件,所以本文分享了如何封裝一個通用的雷達圖控件,希望對大家有所幫助
    2023-08-08
  • C#8.0 中開啟默認接口實現(xiàn)方法

    C#8.0 中開啟默認接口實現(xiàn)方法

    這篇文章主要介紹了C#8.0 中開啟默認接口實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧的相關資料
    2019-05-05
  • 利用C#實現(xiàn)AOP常見的幾種方法詳解

    利用C#實現(xiàn)AOP常見的幾種方法詳解

    AOP面向切面編程(Aspect Oriented Programming),是通過預編譯方式和運行期動態(tài)代理實現(xiàn)程序功能的統(tǒng)一維護的一種技術。下面這篇文章主要給大家介紹了關于利用C#實現(xiàn)AOP常見的幾種方法,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-09-09
  • Unity3D獲取當前鍵盤按鍵及Unity3D鼠標、鍵盤的基本操作

    Unity3D獲取當前鍵盤按鍵及Unity3D鼠標、鍵盤的基本操作

    這篇文章主要介紹了Unity3D獲取當前鍵盤按鍵及Unity3D鼠標、鍵盤的基本操作的相關資料,需要的朋友可以參考下
    2015-11-11

最新評論

灵丘县| 南安市| 屯门区| 合作市| 海安县| 长乐市| 双城市| 河北区| 曲靖市| 泰和县| 仙游县| 灵武市| 常宁市| 天津市| 仁寿县| 佛学| 津市市| 大城县| 三穗县| 枣强县| 莲花县| 汕尾市| 长寿区| 神农架林区| 德兴市| 临高县| 吉木乃县| 永福县| 河北区| 阿克陶县| 湖州市| 宁安市| 灵山县| 广水市| 高淳县| 元朗区| 榆中县| 韩城市| 北海市| 临漳县| 雷州市|