public void fun(int[] a, int[] b)
{
int alength=a.Length;
int blength=b.Length;
int [,] c;
if(alength>blength)
c=new int[2,alength];
else
c=new int[2,blength];
for (int i = 0; i < c.Rank; i++)
{
switch (i)
{
case 0:
for (int j = 0; j < alength; j++)
{
c[i, j] = a[j];//将c数组中的第i行第j列赋值为a[j],此时i为0
}
break;
case 1:
for (int j = 0; j < blength; j++)
c[i, j] = b[j];//将c数组中的第i行第j列赋值为b[j],此时i为1
break;
}
}
for (int i = 0; i < c.Rank; i++)
{
for (int j = 0; j < c.GetUpperBound(c.Rank - 1)+1; j++)
{
Console.Write(c[i, j] + " ");
}
}
Console.ReadKey();
}rank()函数获得二维数组的轶。例如int[,] a=new int[2,4],此时a.rank=2;c.GetUpperBound(c.Rank - 1)+1的作用是获取c数组的第c.rank-1维的数组上限。
在主函数中调用
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4, 5, 6, 7 };
int[] b = { 12, 23, 56, 99, 100,22,11 };
Program p = new Program();
p.fun(a, b);
}
|