我正在制作一个小游戏来帮助我学习c#。到目前为止,我所做的全部都添加了一些变量,如fullName,firstName和lastName,以便稍后可以引用它们。这工作得很好。但是当我想到添加诸如Mr.或Ms.这样的名称前缀(我在代码中将它们称为“标题”)的问题时,控制台只是打开了空白。这里是我的代码...当运行我的基本c#控制台应用程序时,我的控制台打开空白,我不知道为什么
using System;
namespace My_Fist_Console_Game
{
class Program
{
static void Main(string[] args)
{
string userValue = Console.ReadLine();
Console.WriteLine("Airport Sim: Console Edition (literally)");
Console.Write("Type your first name here: ");
string firstName = Console.ReadLine();
Console.Write("Type your last name here: ");
string lastName = Console.ReadLine();
string title;
Console.Write("are you male or female?");
if ((userValue == "male") || (userValue == "Male"))
{
title = "Mr. ";
}
else if ((userValue == "female") || (userValue == "Female"))
{
title = "Ms. ";
}
string fullName = firstName + " " + lastName;
Console.ReadLine();
Console.Clear();
Console.WriteLine("Flight Attendant: ");
Console.WriteLine(" Hello " + title + " " + lastName);
Console.ReadLine();
}
}
}
谢谢!现在我删除了“userValue = Console.ReadLine();”,我该怎么做,以便if语句中的userValue仍然可以识别男性,男性,女性等? – Valorum
请参阅Willy的答案,了解如何对其进行修改以便仍然有效 – BradleyDotNET