Tuesday, 10 September 2013

How to combine two different strings in one string in c#

How to combine two different strings in one string in c#

I have checked most of the questions might contain my solution but I
couldn't find any. Or maybe I didn't understand. So, here is my question:
I want to combine two strings in one and keep using it alone.
My strings:
static string name = ""; (for example: John or Jane)
static string gender = ""; (for example: Mr. or Mrs.)
and I want to combine these two in one like this:
static string player = gender+name;
Console.writeline("Hello "+player);
and I want to see it in my console like this:
Hello Mr.John or Hello Mrs.Jane
I didn't want to mention console.readline parts. There will be entries
where I will type name and gender. Thanks
EDIT:
This is what I did (Sorry, it take too long):
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();
}
These result like "Welcome __"

No comments:

Post a Comment