c# - 控制台不显示但第一行
问题描述
我们正在尝试在控制台上编写 3 个数组
像这样;
DDDEEDUDE
教育
到期
随机选择给定的数组和字母代码运行得很好,但它只显示第一行。我想不出一个好主意。第一个数组运行完美,但其他数组不显示。
string[] A1 = new string[15];
string[] A2 = new string[15];
string[] A3 = new string[15];
Random rastgele = new Random();
int selected_array = 0;
int gamecount_for_a1 = 0;
int gamecount_for_a2=0;
int gamecount_for_a3=0;
string which_letter_str;
while (true)
{
int which_array = rastgele.Next(3);
if (which_array == 0)
{
selected_array = 0;//A1
}
else if (which_array == 1)
{
selected_array = 1;//A2
}
else
{
selected_array = 2;//A3
}
int which_letter_int= rastgele.Next(3);
if (which_letter_int == 0)
{
which_letter_str = "D";
}
else if (which_letter_int == 1)
{
which_letter_str = "E";
}
else
{
which_letter_str = "U";
}
if (selected_array ==0)
{
A1[gamecount_for_a1] = which_letter_str;
Console.SetCursorPosition(gamecount_for_a1, 0);
Console.Write(A1[gamecount_for_a1]);
gamecount_for_a1++;
}
else if (selected_array == 1)
{
A1[gamecount_for_a2] = which_letter_str;
Console.SetCursorPosition(gamecount_for_a2, 2);
Console.Write(A2[gamecount_for_a2]);
gamecount_for_a2++;
}
else
{
A1[gamecount_for_a3] = which_letter_str;
Console.SetCursorPosition(gamecount_for_a3, 4);
Console.Write(A3[gamecount_for_a3]);
gamecount_for_a3++;
}
Console.ReadLine();
if (gamecount_for_a1 == 15 || gamecount_for_a2 == 15 || gamecount_for_a3 == 15)
break;
}
解决方案
您的代码中有两个错误:
A1[gamecount_for_a2]
A1[gamecount_for_a3]
数组应该是 A2 和 A3。
推荐阅读
- c++ - 如何将深度 = 17 的 DicomImage(Dcmtk) 转换为 Mat(Opencv) 对象?
- java - 如何自动重新连接到 XMPP 服务器?
- java - Hibernate 将关联映射为映射
- eclipse - 多个模块的 GWT+ Maven 和 Eclipse 编译
- informatica - 使用 informatica 存储库表查询以获取从源到目标的字段到字段逻辑
- sql - 转换 DATE 会返回“无效月份”错误
- java - Logstash-logback 事件特定的自定义字段(使用 StructuredArguments)未添加到 JSON
- c - 从单个文件描述符多路复用到两个文件描述符
- xml - 在 rtf 模板中显示正确的数据
- python - 拟合列表的线性组合