1,针对一维数组
方法一:
string[] arrayCity = { "BeiJing","TianJin", "HongKong" };
方法二:
string[] arrayCity ;
arrayCity = new string[3]{ "BeiJing","TianJin", "HongKong" };
方法三:
string[] arrayCity = new string[3];
arrayCity[0] = "BeiJing";
arrayCity[1] = "TianJin";
arrayCity[2] = "HongKong";
2,针对二维数组
方法一:
string[,] multiArrayCity = { { "BeiJing","TianJin", "HongKong" }, { "WuHan", "ChangSha", "ChongQing" } };
方法二:
string[,] multiArrayCity = new string[2,3]{ { "BeiJing","TianJin", "HongKong" }, { "WuHan", "ChangSha", "ChongQing" }};
方法三:
string[,] multiArrayCity = new string[2, 3];
multiArrayCity [0,0] = "BeiJing";
multiArrayCity [0,1] = "TianJin";
multiArrayCity [0,2] = "HongKong";
multiArrayCity [1,0] = "WuHan";
multiArrayCity [1,1] = "ChangSha";
multiArrayCity [1,2] = "ChongQing"; |