c# - 有没有人可以解决这个 if 语句
问题描述
static void Main(string[] args)
{
string name01;
string name02;
Console.WriteLine("Welcome to Choice RPG! <press enter to start your adventure>");
Console.ReadKey();
Console.WriteLine("Enter your Adventurers name! <press enter to continue>");
name01 = Convert.ToString(Console.ReadLine());
Console.WriteLine(name01 + "! come on, you can think of a better name than that can't you? <press enter to continue>");
Console.ReadKey();
Console.WriteLine("Enter your Adventurers name! <press enter to continue>");
name02 = Convert.ToString(Console.ReadLine());
if (name02 == name01)
{
Console.WriteLine("Wow, i guess you really like that name huh, fine.");
}
else
{
Console.WriteLine("Now thats more like it!");
}
}
这是我的第一个一般编程项目。我正在制作一个 RPG 游戏,您可以在其中选择冒险,这是用户的游戏名称。
一切正常,直到 if 语句(之后 cmd 刚刚关闭)。如果有人有任何想法来解决它,请告诉我。
解决方案
代码对我来说看起来不错,尝试添加:
Console.WriteLine("Press <ENTER> to exit");
Console.Readline();
最后查看您要显示的消息是否实际在应用程序退出和关闭之前显示。我的猜测是您在 Visual Studio 中运行,并打印了消息,但是执行窗口关闭得如此之快,以至于您看不到它。
推荐阅读
- assembly - ARMv7 中的 Unalias 命令?
- node.js - 在 NestJS HTTP 服务器中使用子进程时,受 CPU 限制的进程会阻塞工作池
- excel - Excel - 超过 500k 行的 Vlookup 公式 - 如何加快速度?
- swift - 使用谓词获取核心数据
- jquery - Jquery验证不允许输入字段为零
- c# - 在 C# 中搜索 Json 文件中的字段
- r - R读取excel文件数值精度问题
- css - 包含在具有表单组引导类的 div 内的 HTML 元素,显示在 div 之外,这是故意的吗?
- python - 如何更改 matplot lib 中的默认值并找到特定的 rc 参数列表
- c# - 在两个线程之间传递数据时,是什么确保线程看到最新值?