class matrix
{
private int[,] a;
private int x;
private int y;
public Int32 this[Int32 i, Int32 j]
{
get
{
return a[i, j];
}
set
{
a[i, j] = value;
}
}
public Int32 X
{
get
{
return x;
}
}
public Int32 Y
{
get
{
return y;
}
}
public matrix(int x, int y)
{
this.x = x;
this.y = y;
a = new int[x, y];
Random m1 = new Random();
for (Int32 i = 0; i < x; i++)
{
for (Int32 j = 0; j < y; j++)
{
a[i, j] = m1.Next(100);
}
} }
public static matrix add(matrix a, matrix b)
{
if (!(a.X == b.X && a.Y == b.Y))
return null; matrix m = new matrix(a.X,a.Y); for (int i = 0; i < a.X; i++)
for (int j = 0; j < a.Y; j++)
m[i,j] = a[i,j] + b[i,j]; return m;
}
public void printarry()
{
for (Int32 i = 0; i < x; i++)
{
for (Int32 j = 0; j < y; j++)
{
Console.Write(a[i,j] + " ");
}
Console.WriteLine();
}
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货