Answers for "c# enter key press console"

C#
1

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...
  
}
Posted by: Guest on September-16-2020

C# Answers by Framework

Browse Popular Code Answers by Language