Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Can Someone help mw with this code?

My goal is to have some sort of a psychologist to an user, but the code is incorrect....

static void Main(string[] args)


      Console.WriteLine("So, how was your day? Press G for Good or B for Bad.");


      if (Console.ReadKey().Key != ConsoleKey.G) ;


        Console.WriteLine("And Why's that, have you got like a desease or something?");


      if else Console.ReadKey().Key != ConsoleKey.B;


        Console.WriteLine("Good to hear that! Any other news?");




  • Console.ReadKey() returns a ConsoleKeyInfo object that you need to save in order for your comparison to work properly (otherwise, by calling Console.GetKey() again you actually wait for the user to insert another key)

    To fix it:


    var keyInfo = Console.ReadKey();

    if (keyInfo.KeyChar == "g") {

    ... } else if (keyInfo.KeyChar == "b") {

    ... }

Sign In or Register to comment.