Toby Mak
0
Q:

c# enter key press console


// ---------- How to detect when the input is ENTER? ----------- //

string input = "";

// 1º Method
while(true)
{
  Console.WriteLine("Write something (or hit ENTER to quit): ");
  input = Console.ReadLine();
  
  if( string.IsNullOrWhiteSpace(input)) )
    break;
  else
    // some code...
  
}


// 2º Method
while(true)
{
  Console.WriteLine("Write something (or hit ENTER to quit): ");
  input = Console.ReadLine();
  
  if( input.Equals("") )
    break;
  else
    // some code...
  
}
 
1

New to Communities?

Join the community