数组可以是一维、多维或交错数组
数值数组元素的默认设置为0,而引用元素的默认设置为null。【需要牢记,很多if语句需要用到】
交错数组是数组的数组,因此起元素是引用类型并初始化为null。
数组的索引从零开始:具有n个元素的数组的索引是从0到n-1。【这个新手经常犯错误】
class testarraysclass
{
static void main()
{
//declare a single-dimensional aray
int[] array1 = new int[5];
//declare and set array element values
int[] array2 = new int[]{1,2,3,4,5};
//alternative syntax
int[] array3 ={1,2,3,4,5};
//declare a two dimensional array
int[,] multidimensionalarray1 = new int[2,3];
//declare and set array element values
int[,] multidimensionalarray2 = {{1,2,3},{1,2,3}};
//declare a jagged array
int[][] jaggedarray = new int[6][];
//set the values of the first array in the jagged array structure
jaggedarray[0] = new int[4] {1,2,3,4};
}
}
看一些.net 一些常用的数组操作
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"的数组元素,只删除一次,如果要全删,需要做循环
-------------------------------------------------------------
listitem newitem=new listitem();newitem.text="a";newitem.value="b";
mydropdown.items.add(newitem);//使用listitem为list框添加项
-------------------------------------------------------------
hashtable ht =new hashtable();ht["1"]="a";ht.add("2","a");//hashtable用法
sortedlist sl=new sortedlist();sl["1"]="a";sl.add("2","a");//sortedlist用法,会自动根据key进行排序
foreach(dictionaryentry abc in sl) //遍历sortedlist的办法
樱花校园模拟器4399中文版
樱花校园模拟器4399中文版,十分奇趣好玩的3d校园冒险模拟
我的暑假秘密回忆繁星新春版
我的暑假秘密回忆繁星新春版是一款少女模拟养成类休闲游戏。这款
樱花校园模拟器国际版
樱花校园模拟器国际版,一个超级自由超级好玩的自由恋爱模拟的游
饥荒海难九游版
饥荒海难九游版,带你去真实的海岛上感受一下什么才是真正的孤岛
盖瑞模组体验版最新版
盖瑞模组体验版是玩法非常丰富多元化的沙盒建造游戏,玩家可以在