Asp.net数组[转]

string[] abc=new string[8]{"1","2","3","4","1","2","3","4"};
Response.Write(Array.IndexOf(abc,"3",1));//在abc数组中查找"3",从abc[1]开始找
Response.Write(Array.LastIndexOf(abc,"3"));//在abc数组中查找"3",从最后开始找

string[] abc=new string[8]{"1","2","3","4","1","2","3","4"};
Response.Write(Array.IndexOf(abc,"3",1));//在abc数组中查找"3",从abc[1]开始找
Response.Write(Array.LastIndexOf(abc,"3"));//在abc数组中查找"3",从最后开始找
——————————————————————————
string[] arrStr=new string[8]{"1","4","3","2","16","14","12","14"};//arrStr[0]="1"…arrStr[7]="14"
Array.Reverse(arrStr); //颠倒arrStr数组,此时arrStr[0]="14"…arrStr[7]="1"
Array.Sort(arrStr); //给数组排序,此时顺序为1,12,14,14,16,2,3,4(因为是按字符串排序)
——————————————————————————
Array型数组要重定义大小,必须用ReDim(VB),对于大数组会特别慢;且无法在中间插入元素;不能清除它们(只能设置为空或0)
ArrayList在使用上比Array慢,但是不用重定义大小,使用myArrList.Add("Dog")s可以方便的添加数据
ArrayList myArrList = new ArrayList();//不用指出数组的大小,而且每个元素可以是任意数据类型;
myArrList.Insert(1,"abc"); //插入元素到数组[1]前
myArrList.RemoveAt(1); //删除数组元素[1]
myArrList.Remove("abc"); //删除内容为"abc"的数组元素,只删除一次,如果要全删,需要做循环
——————————————————————————
 

发表评论

电子邮件地址不会被公开。 必填项已用*标注