Answers for "console readkey"

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
2

Console.ReadKey();

using System;

	namespace GrepperAnswer
    {
    	public class Answer
        {
        	static void Main(string[] args)
            {
            
            		Console.ReadKey();
                    
            }
       	
        }
        
    }
Posted by: Guest on March-16-2021

C# Answers by Framework

Browse Popular Code Answers by Language