怎么知道数组的大小?

来源:百度知道 编辑:UC知道 时间:2024/06/06 01:49:01
string a="asdfas/sdfaf/dfgsd/dsfgsd/dfgsd/gfsdfsd/sdfsdf/sdg/dfgdsfg/sd/fg/sdgfsdfg/d/gdf/ge/rgtasdf";
string[] loaction=a.Split('/');
int i=1;
string name = string.Empty;
while (null!=loaction[i]) //错误处
{
name = loaction[i];
Response.Write("<br/>" + name);
i++;
}

i超过时不能用,显示错误Index was outside the bounds of the array.
我怎么知道i最大可以是多少.

loaction.length

总长度为:i<location.length;

太复杂了,看不懂.

貌似一楼说对了~loaction.length() 但对i<=loaction.length绝对成立的~因为数组有很多个值啊~先loaction.length()出来看下有几个值先吧~

总长度为:i<location.length;

数组的大小分几种情况:
1.一维数组
i<=loaction.length
2.多维数组
(1)取得所有元素个数
i<=loaction.length
(2)取得各维的元素数
loaction.GetLength(0) //取得第一维的元素数
loaction.GetLength(1) //取得第二维的元素数
......
依此类推
(3)取得数组的维数
loaction.Rank //一维数组为1,二维数组为2,依此类推

3.数组的数组
基本上与上述类似
例:Dim Kumi(2)() As Integer
Dim Seito1() As Integer = {11, 22}
Kumi(0) = Seito1 //如果没赋值的话,会出错
TextBox4.Text = Kumi(0).GetLength(0)