一个很困扰人的问题!小弟我正在自学……望能给解释
问题代码:class Program
{
static void Main(string[] args)
{
Program myClass1 = new Program();
int[,] arrayA = new int[2, 3];
int[,] arrayB = new int[3, 2];
for (int i = 0; i < 2; i++ )
{
for (int j = 0; j < 3; j++ )
{
arrayA[2, 3] = i + j + 10;
}
}
Console.WriteLine("以下输出矩阵arrayA结构!!");
myClass1.为什么这里调不出printfArray()方法呢?
}
}
课本源码:
class Matrixm
{
static void Main()
{
Matrixm myClass1 = new Matrixm();
int[,] arrayA = new int[2, 3];
int[,] arrayB = new int[3, 2];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
arrayA[i, j] = i + j + 10;
}
}
Console.WriteLine("以下输出矩阵 arrayA 结构 !! ");
myClass1.PrintArray(arrayA, 2, 3);这里又可以?
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
arrayB[i, j] = i + j + 1;
}
}
Console.WriteLine("以下输出矩阵 arrayB 结构 !! ");
myClass1.PrintArray(arrayB, 3, 2);
Console.WriteLine("将矩阵 arrayA 与 arrayB 相乘输出其结果 !! ");
myClass1.DMartix(arrayA, arrayB);
Console.ReadLine();
}
void PrintArray(int[,] intArray, int row, int column)
{
for (int i = 0; i < row; i++)
{
Console.Write("\n");
for (int j = 0; j < column; j++)
{
Console.Write(intArray[i, j] + "\t");
}
Console.Write("\n");
}
Console.Write("\n");
}
void DMartix(int[,] arrayA, int[,] arrayB)
{
int[,] resultArray = new int[2, 2];
int result = 0;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
result = 0;
for (int k = 0; k < 3; k++)
result = result + arrayA[i, k] * arrayB[k, j];
resultArray[i, j] = result;
}
}
PrintArray(resultArray, 2, 2);
}
}