Click to See Complete Forum and Search --> : Console string manipulating


ShutdownLx
July 26th, 2009, 01:53 PM
Hey, this may sound nooby, I'd like to know how to correctly manipulate Console.ReadLine(); .

switch (Console.ReadLine())
{
case"server":
Chat_Server.SimpleServer.Function();
Console.Title = "Server";
Console.ReadLine();
break;
case"client":
Chat_Server.Client.ClientConnect();
Console.Title = "Client";
Console.ReadLine();
break;
}

If I use this, I have to retype the cases 3 times (Until the third line) for it to take effect.. Here's an image for example.


Here's the whole script

Console.ForegroundColor = ConsoleColor.Green; Console.Write("[MENU]");
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("What kind of user are you?\n\n\n \n 1-Type ''Server'' if you wish to start a server. \n 2- Type ''Client'' if you wish to connect to a server.");
Console.ReadLine();
Console.ReadLine().ToLower();
switch (Console.ReadLine())
{
case"server":
Chat_Server.SimpleServer.Function();
Console.Title = "Server";
Console.ReadLine();
break;
case"client":
Chat_Server.Client.ClientConnect();
Console.Title = "Client";
Console.ReadLine();
break;
}

Any ideas? :S

dannystommen
July 26th, 2009, 03:24 PM
That's because you have Console.WriteLine 3 times in your code


Console.ForegroundColor = ConsoleColor.Green; Console.Write("[MENU]");
Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("What kind of user are you?\n\n\n \n 1-Type ''Server'' if you wish to start a server. \n 2- Type ''Client'' if you wish to connect to a server.");
string user_type = Console.ReadLine();
switch (user_type.ToLower())
{
case"server":
Chat_Server.SimpleServer.Function();
Console.Title = "Server";
Console.ReadLine();
break;
case"client":
Chat_Server.Client.ClientConnect();
Console.Title = "Client";
Console.ReadLine();
break;
}