首页 > 解决方案 > 有没有人可以解决这个 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 刚刚关闭)。如果有人有任何想法来解决它,请告诉我。

标签: c#

解决方案


代码对我来说看起来不错,尝试添加:

Console.WriteLine("Press <ENTER> to exit");
Console.Readline();

最后查看您要显示的消息是否实际在应用程序退出和关闭之前显示。我的猜测是您在 Visual Studio 中运行,并打印了消息,但是执行窗口关闭得如此之快,以至于您看不到它。


推荐阅读