我正在製作一個小遊戲來幫助我學習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