How would I wait for input in C# using a method other than Console.ReadKey()
? I don't need the input, I just need a pause. Console.Readkey()
works fine, but it shows what you pressed. For example, the code below would work fine, but shows the key you pressed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Example
{
class Program
{
static void Wait()
{
Console.Write("\nPress Any Key To Continue");
Console.ReadKey();
}
static void Main(string[] args)
{
//some code
Wait();
//some other code
Wait();
}
}
}
For example, the code below would work fine, but shows the key you pressed.
To solve this problem, use the intercept parameter:
Console.ReadKey(true);
From MSDN :
intercept (System.Boolean)
Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false .
u can use thread.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;
namespace Demo
{
class Program
{
static void Main(string[] args)
{
WriteLine("This is a demo!");
Thread.Sleep(1000);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.