一、一维:
int[] numbers = new int[]{1,2,3,4,5,6}; //不定长
int[] numbers = new int[3]{1,2,3};//定长
二、多维
int[,] numbers = new int[,]{{1,2,3},{1,2,3}}; //不定长
int[,] numbers = new int[2,2]{{1,2},{1,2}}; //定长

三、例子
A:int[] mf1=new int[6];
      //注意初始化数组的范围,或者指定初值; //包含6个元素的一维整数数组,初值1,2,3,4,5,6
      int[] mf2=new int[6]{1,2,3,4,5,6};

B://一维字符串数组,如果提供了初始值设定项,则还可以省略 new 运算符
      string[] mf3={"c","c++","c#"};

C://一维对象数组
      Object[] mf4 = new Object[5] { 26, 27, 28, 29, 30 };

D://二维整数数组,初值mf5[0,0]=1,mf5[0,1]=2,mf5[1,0]=3,mf5[1,1]=4
      int[,] mf5=new int[,]{{1,2},{3,4}};

E://6*6的二维整型数组
      int[,] mf6=new mf[6,6]; 

四、取得数组元素个数:
        int   b;  
        b   =   sizeof   (a)/sizeof   (*a);


C#创建动态数组


using System; 
using System.Collections; 
public class SC 

static void Main() 

  ArrayList al
=new ArrayList(); 
  al.Add(
"Hello"); 
  al.Add(
" "); 
  al.Add(
"World"); 
  al.Add(
"!"); 
  
string[] str=new string[al.Count]; 
  al.CopyTo(str,
0);//从第0个位置开始复制 
  for(int i=0;i<str.Length;i++
  

   Console.WriteLine(i.ToString()
+str[i]); 
  }
 
}
 
}

­

posted on 2008-03-27 21:09  jalor  阅读(1156)  评论(0)    收藏  举报