c# - 为什么 void Main 在 if 条件之后不启动?
问题描述
Void Main
在 if 语句之后不会重新开始。
我已经用这种结构进行了一段时间的试验,通常它们可以工作。但事实并非如此。生成器空洞在下面的某个地方,请不要考虑它。
class Program
{
private static string Input = Console.ReadLine();
static void Main()
{
Console.WriteLine("Press any key to start");
Program.Generator();
Console.WriteLine("Are you satisfied? Type '1' if yes or '2' if no.");
Console.ReadLine();
if (Input == "2")
Program.Main();
}
}
没有错误,没有错误,控制台只是在完成后关闭Main
。
解决方案
欢迎来到堆栈溢出。你不是疯了,只是错过了一段关于编程和控制流的信息。具体来说,迭代语句。
您编写的程序将随时退出Input
并保留一个值,而不是2
因为没有循环迫使它一遍又一遍地运行。
static void Main()
{
Console.WriteLine("Press any key to start");
Console.ReadKey();
do
{
// Program.Generator();
Console.WriteLine("Are you satisfied? Type '1' if yes or '2' if no.");
} while (Console.ReadKey().KeyChar != '1');
}
推荐阅读
- javascript - 如何自定义 HTML5 视频下载按钮
- php - 如何在 PHP 中进行 sql 嵌套/子查询
- jquery - 防止 JQM 导致页面在表单提交时滚动到顶部
- c# - 具有正确距离的 WriteLine/Print Arraylist
- python - 将 Pandas DataFrame 中的过滤行替换为另一个 DataFrame
- pddl - PDDL 如何为多个谓词分配编号
- php - 根据用户角色向未登录用户显示 WooCommerce 折扣的可能折扣
- javascript - 有没有一种简单的方法来提及所有 Discord 用户的角色?
- sql - oracle sql:“获取或插入”存储过程
- python - list_filter 以选择作为值