C# 有没有一种方法可以返回并在一行中添加一些内容';已经印好了吗?
我有一个函数可以启动并打印矩阵C# 有没有一种方法可以返回并在一行中添加一些内容';已经印好了吗?,c#,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
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;
但是它在矩阵后面打印一行,但是我想在已经打印的矩阵中的每一行之后打印。我有办法做到这一点吗
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
对不起,如果这是一个愚蠢的问题,我是初学者
编辑:谢谢大家的回答,我将与
控制台一起玩。设置光标或位置并使其变得漂亮这是您想要的吗
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();
}
static void Main(字符串[]args)
{
对于(变量i=0;i<5;i++)
{
控制台写入线(“1,2,3,4,5”);
}
控制台。设置光标位置(10,0);
Console.Write(“您在这里得到了x个正确的预测”);
Console.ReadKey();
}
控制台。SetCursorPosition
:@B0Andrew单个数字会弄乱吗?还有一种方法可以在不计算空格的情况下完成吗?是的,但我有一个后续问题:一位数的数字会把事情搞砸吗(6个两位数的数字会比5个两位数的数字和一个一位数的数字长)。有没有一种方法可以在不计算空格的情况下实现这一点?@mufinator您可能希望根据最大值格式化矩阵(或者在您的案例测试中,如果您有任何值>=10)。那么矩阵的每一行都将具有相同的长度:@mufinator是的,它可以。如果第一个参数太小,将替换打印的数字。因此,您最好为所有数字设置一个固定的字段宽度,或者干脆将每个打印行保存到一个数组中。
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();
}