我檢查了大多數問題可能包含我的解決方案,但我找不到任何問題。或者,也許我不明白。所以,這是我的問題:如何在一個字符串中組合兩個不同的字符串?
我想將兩個字符串結合在一起並單獨使用它。
我的字符串:
static string name = ""; (for example: John or Jane)
static string gender = ""; (for example: Mr. or Mrs.)
,我想這兩個在一個像這樣的組合:
static string player = gender+name;
Console.writeline("Hello "+player);
,我想看到它在我的控制檯是這樣的:
Hello Mr.John or Hello Mrs.Jane
我不想提及console.readline部分。將會有我將輸入姓名和性別的條目。 感謝
編輯:
這是我做的(對不起,這要花很長時間):
static string name = "";
static string gender = "";
static string player = name + gender;
static void Main(string[] args)
{
Console.WriteLine("Welcome. What is your name?");
name = Console.ReadLine();
Console.WriteLine("Sex?\n-Male\n-Female");
gender = Console.ReadLine();
Console.WriteLine("Press Enter to continue");
Console.ReadLine();
Console.WriteLine("Welcome"+player);
Console.ReadLine();
}
這些結果,如 「歡迎__」
我沒有看到問題... – UIlrvnd
你有沒有試過這個? –
你已經做到了 - static string player = gender + name; – Lev