首页 > Windows开发 > 详细

c#中的Rank属性和GetUpperBound,GetLowerBound(0)方法

时间:2015-09-27 18:55:19      阅读:1582      评论:0      收藏:0      [点我收藏+]

今天使用数组的时候,用到了几个数组的属性,总结如下:

Array的Rank 属性:
语法:public int Rank { get; } 得到Array的秩(维数)。
Array的GetUpperBound 方法:
语法:public int GetUpperBound(int dimension) 用于获取 Array 的指定维度的上限
Array的GetLowerBound方法:
语法:public int GetLowerBound(int dimension) 用于获取 Array 的指定维度的下限
举例如下:

int []a=new int[3];

这样的话,a.Rank就等于1,表示这是一个一维数组


string[,] Arr= new string[,]{{"1","2"},{"3","4"},{"5","6"}}; 

这样的话,Arr.Rank就为2,表示这是一个二维数组
for(int i=Arr.GetLowerBound(0);i<=Arr.GetUpperBound(0);i++)

//Arr.GetLowerBound(0);其中的0表示取第一维的下限,一般数组索引是0开始,为0

//同理可得Arr.GetUpperBound(0);其中的0表示取第一维的上限,在本例中是3行2列的数组,所以为3-1=2
for(int j=Arr.GetLowerBound(1);j<=Arr.GetUpperBound(1);j++)
{

//Arr.GetLowerBound(1);其中的1表示取第二维的下限,一般数组索引是0开始,为0

//同理可得Arr.GetUpperBound(1);其中的1表示取第二维的上限,在本例中是3行2列的数组,所以为2-1=1


//遍历数组的元素

Console.write(Arr[i,j]);
}


c#中的Rank属性和GetUpperBound,GetLowerBound(0)方法

原文:http://my.oschina.net/wdqipai/blog/511671

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!