有没有办法可以返回并添加一些已经打印过的行?

时间:2015-04-20 11:22:05

标签: c#

我有一个启动并打印出矩阵的函数

int[,] LotteryArray = new int[Rows,Columns];

        for (int i = 0; i < LotteryArray.GetLength(0); i++) 
        {
            for (int j = 0; j < LotteryArray.GetLength(1); j++)
            {
                LotteryArray[i, j] = RandomNum(1, 46);   
                Console.Write("{0,3},", LotteryArray[i, j]);
            }
            Console.WriteLine();
        }
        return LotteryArray;

我有另一个函数,调用LotteryArray,然后检查它的每一行,看看是否有“获胜”数字,然后打印出每行中有多少“获胜”数字。

我做了这个

for (int j = 0; j < LotteryArray.GetLength(0); j++) 
        {
            for (int k = 0; k < LotteryArray.GetLength(1); k++)
            {
                for (int i = 0; i < Winner.Length; i++)  
                {
                    if (Winner[i] == LotteryArray[j, k])
                    {
                        Prediction++;
                    }
                }
            }
            RowNum++;
            Console.WriteLine("You got {0} predictions correct in row {1}", Prediction, RowNum);
            Prediction = 0;
        }

但它在矩阵后面打印出一行,但我想在已经打印的矩阵中的每一行之后打印出来。我有办法做到这一点吗?

1,2,3,4,5
1,2,3,4,5
1,2,3,4,5
you got yada yada yada in line 1
you got yada yada yada in line 2 
you got yada yada yada in line 3

是它的样子

我希望看起来像这样

1,2,3,4,5      you got x predictions correct here
1,2,3,4,5      yada yada yada
1,2,3,4,5      yada yada yada
抱歉,如果这是一个愚蠢的问题,我是初学者

编辑:谢谢大家使用Console.SetCursorPosition来解决问题的答案,并让它变得漂亮

1 个答案:

答案 0 :(得分:1)

这是你想要的吗?

static void Main(string[] args)
{
    for (var i = 0; i < 5; i++)
    {
        Console.WriteLine("1,2,3,4,5");
    }
    Console.SetCursorPosition(10, 0);
    Console.Write("you got x predictions correct here");
    Console.ReadKey();
}