Wednesday 16 November 2011

C# Console Application – Pause for User Input / Pause Command in C# Console Application

In some cases you may require to pause for the user input or display a message to the user and prompt him to continue by pressing the key.

ReadKey does the trick. It obtains the next character or function key pressed by the user.
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
If you want the key to be displayed on user window, you can set the parameter to be false. You can also get the pressed key using as ConsoleKeyInfo shown below
Console.WriteLine("Press any key to continue...");
System.ConsoleKeyInfo KInfo = Console.ReadKey(true);
Console.WriteLine("You have pressed :" + KInfo.Key.ToString());
Press any key to continue in C#, C# Console Application Wait, Wait for user input in C# Console Application, C# Console Application, C# ConsoleKeyInfo, C# KeyPress in Console Application
Press any key to continue in .NET, .NET Console Application Wait, Wait for user input in .NET Console Application, .NET Console Application


No comments:

Post a Comment