0
我正在使用C#,我试图乘以一个矩阵的标量并返回结果。我有的问题是可以通过两种方式传递参数。它们可以以标量形式出现在矩阵中,或者矩阵然后是标量形式,所以我需要设置两种方法来处理它们。我知道我可以简单地在第二种方法中复制代码,但据我了解,方法调用是一种更简单的方法,因为两种方法都使用相同的代码。我只需要一些帮助,看看这个电话会是什么样子。我的代码如下所示。调用同一类中的另一个方法内的方法
public static Matrix operator*(int scalar, Matrix matrix)
{
uint row,col;
Matrix matrixProd;
matrixProd = new Matrix(matrix.Rows,matrix.Cols);
for (row=1; row<=matrixProd.Rows; row++)
for (col=1; col<=matrixProd.Cols; col++)
matrixProd.TwoDArray[row,col] = matrix.TwoDArray[row,col] * scalar;
return matrixProd;
}
public static Matrix operator*(Matrix matrix, int scalar)
{
//I have no idea on what to put here to call the previous method.//
}
你试图返回标*矩阵; ? – Enam
我没有。这很好。谢谢! – user3029516