unity how to end a game with esc

C#
void Update()
{
    if (Input.GetKey(KeyCode.Escape))
    {
        Application.Quit();
    }
}
Source

Also in C#: