C# Close Console Application on key press

class Program{    static void Main(string[] args)    {        CloseApp();    }    private static void CloseApp()    {        Console.WriteLine("Press 'ESC' or 'X' to Exit");                ConsoleKeyInfo keys;        while (true)        {            keys = Console.ReadKey();            if (keys.Key == ConsoleKey.Escape || keys.Key == ConsoleKey.X) break;            Console.WriteLine();        }    }}

Leave a Reply

Your email address will not be published. Required fields are marked *