I just didn't find this in the Microsoft docs. I tried to use parameters inside brackets in Console.ReadKey();
, but it isn't working.
I need to make the program terminate if the user presses a key other than the one specified in the program message. For example, the program requires the user to press the Enter
key. If the user decides to press a different key, I want the program to terminate.
Example of code:
using System;
namespace ConsoleApp10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Let's try to enter some number and show it in a console? (Press Enter/Return key to continue)");
Console.ReadKey();
Console.WriteLine("Enter your value");
double x = Convert.ToDouble(Console.ReadLine());
Console.WriteLine($"Your value is {x}");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}