欢迎来到天天文库
浏览记录
ID:31707652
大小:58.56 KB
页数:19页
时间:2019-01-17
《c#常用集合总结》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C#常用集合总结C#commoncollectionsummary-1(1)let'sbeginwiththesetdefinition!Personally,Ithinkit'sgoodtolookbackalittlebitmoreoften.Acollectionisagroupofsimilartypedobjectsthatarecombinedtogether・Sowehavetobecarefulwhenchoosingacollectionclass,sinceeachcollectionhasitsowncapabilities
2、,soeachsethasitsownlimitations.Thestrongerthespecializationoftheset,themorerestrictionsitwillhave・(2)ArrayList:theuseofsizecanbeimplementedasanarrayofadditionaldynamicneeds・ArrayListhasacollectionofboxingandunboxingoperations,ArrayListpassedbyvalue・Thecodereadsasfollows:Array
3、Listal=new(ArrayList);//parameterlessconstructor//ArrayListal=new,ArrayList(3)definestheconstructorofthelengthThe//ArrayListal=newArrayList(Newint{1,2,3})implementstheICollectioninterfaceAl.Add(1);//packingAl.Add(2);Al.Add(3);For(inti=0;I4、;Console・WriteLine(al[i]・GetType()・Name);}Console・WriteLine(〃-〃);Foreach(objectKinAl)//unboxing,mustbedeclaredasaobjecttype・{Console・WriteLine(K);}Console.WriteLine(〃-“);NameExplainCapacityGetsorsetsthenumberofe1ementsthatArrayListcancontain.CountGetsthenumberofe1ementsactual5、lycontainedintheArrayList・IsFixedSizeGetsavalueindicatingwhethertheArrayListhasafixedsize・IsReadOnlyGetsavalueindicatingwhethertheArrayListisread-only.ItemGetsorsetstheelementatthespecifiedindex・AddAddobjectstotheendofArrayList・AddRangeAddtheelementsofICollectiontotheendofArr6、ayList・BinarySearchUseabinarysearchalgorithmtolocatespecificelementsinasortedArrayListorpartofit.ClearRemoveallelementsfromArrayList.ContainsDetermineswhetheranelementisinArrayList・CopyToCopyArrayListorpartsofitintoaone-dimensionalarray.EqualsDetermineswhetherthetwoObjectinst7、ancesareequa1.FixedSizeReturnsalistoffixedsizepackagesinwhichelementsareallowedtochange,butarenotallowedtoaddorremove・GetEnumeratorReturnstheenumeratorthatcyclestoaccessArrayList・GetRangeReturnArrayList,ThatrepresentsasubsetoftheelementsinthesourceArrayList・GetTypeGetstheType8、ofthecurrentinstance・IndexOfAzerostartindexthatreturnsthefirstmatcho
4、;Console・WriteLine(al[i]・GetType()・Name);}Console・WriteLine(〃-〃);Foreach(objectKinAl)//unboxing,mustbedeclaredasaobjecttype・{Console・WriteLine(K);}Console.WriteLine(〃-“);NameExplainCapacityGetsorsetsthenumberofe1ementsthatArrayListcancontain.CountGetsthenumberofe1ementsactual
5、lycontainedintheArrayList・IsFixedSizeGetsavalueindicatingwhethertheArrayListhasafixedsize・IsReadOnlyGetsavalueindicatingwhethertheArrayListisread-only.ItemGetsorsetstheelementatthespecifiedindex・AddAddobjectstotheendofArrayList・AddRangeAddtheelementsofICollectiontotheendofArr
6、ayList・BinarySearchUseabinarysearchalgorithmtolocatespecificelementsinasortedArrayListorpartofit.ClearRemoveallelementsfromArrayList.ContainsDetermineswhetheranelementisinArrayList・CopyToCopyArrayListorpartsofitintoaone-dimensionalarray.EqualsDetermineswhetherthetwoObjectinst
7、ancesareequa1.FixedSizeReturnsalistoffixedsizepackagesinwhichelementsareallowedtochange,butarenotallowedtoaddorremove・GetEnumeratorReturnstheenumeratorthatcyclestoaccessArrayList・GetRangeReturnArrayList,ThatrepresentsasubsetoftheelementsinthesourceArrayList・GetTypeGetstheType
8、ofthecurrentinstance・IndexOfAzerostartindexthatreturnsthefirstmatcho
此文档下载收益归作者所有