C# 我想从第二个对角矩阵从右到左在矩阵对角线上画一条十字线
我用二维数组和两个循环做矩阵对角 我有两个crosa一个通过改变颜色线从右到左的按钮我怎么能做到这一点 这是我的代码我用从左到右的按钮画了十字线 现在我想要从右到左的按钮 这是我的密码C# 我想从第二个对角矩阵从右到左在矩阵对角线上画一条十字线,c#,C#,我用二维数组和两个循环做矩阵对角 我有两个crosa一个通过改变颜色线从右到左的按钮我怎么能做到这一点 这是我的代码我用从左到右的按钮画了十字线 现在我想要从右到左的按钮 这是我的密码 static void DisplayMatrixWithCross(int[,] matrix) { for (int row = 0; row < 7; row++) { for (int column =
static void DisplayMatrixWithCross(int[,] matrix)
{
for (int row = 0; row < 7; row++)
{
for (int column = 0; column < 7; column++)
{
if (row == column)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(matrix[row, column] + " ");
}
else if ()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(matrix[row, column] + " ");
}
else {
Console.ForegroundColor = ConsoleColor.White;
Console.Write(matrix[row, column] + " ");
}
}
Console.WriteLine();
}
}
static void DisplayMatrixWithCross(int[,]矩阵)
{
用于(int行=0;行<7;行++)
{
for(int列=0;列<7;列++)
{
if(行==列)
{
Console.ForegroundColor=ConsoleColor.Red;
编写(矩阵[行,列]+“”);
}
如果()
{
Console.ForegroundColor=ConsoleColor.Yellow;
编写(矩阵[行,列]+“”);
}
否则{
Console.ForegroundColor=ConsoleColor.White;
编写(矩阵[行,列]+“”);
}
}
Console.WriteLine();
}
}
我加了一张照片希望你能看到 我这里也有同样的问题。尝试使用.GetLength(0)和.GetLength(1)方法。 您只需要两个IF语句。 让我向您展示我的代码,到目前为止,我只有这些:
static void DisplayMatrixWithCross(int[,] matrix)
{
for (int row = 0; row < matrix.GetLength(0); row++)
{
for (int col = 0; col < matrix.GetLength(1); col++)
{
if (row == (col - 5) + 5)
{
Console.BackgroundColor = ConsoleColor.Green;
}
Console.ResetColor();
if (row == (col + 5) - 5)
{
Console.ForegroundColor = ConsoleColor.Red;
}
Console.Write("{0,3} ", matrix[row, col].ToString("00"));
}
Console.WriteLine();
}
}
static void DisplayMatrixWithCross(int[,]矩阵)
{
for(int row=0;row