Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:44:23+00:00 2026-05-27T05:44:23+00:00

I have a tiny command line utility which reads user input and adds all

  • 0

I have a tiny command line utility which reads user input and adds all input to a list. When the Esc key is pressed, the program is quit. However, upon pressing the Esc key, even the Escape key is being added to list and then the program quits.

How can I prevent the Esc key from being added to the list?

Code:

    ConsoleKeyInfo cki;
    List<string> stuffs = new List<string>();

    Console.WriteLine("Press Escape (Esc) to quit the program.");

    do {
        cki = Console.ReadKey();
        stuffs.Add(cki.Key.ToString());
        Console.WriteLine();
    } while(cki.Key != ConsoleKey.Escape);

    Console.WriteLine("You have entered the following data:");

    foreach(string stuff in stuffs)
        Console.WriteLine(stuff);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:44:23+00:00Added an answer on May 27, 2026 at 5:44 am

    Change the loop so that you check the value prior to adding it to your list. For example, this loops the same, but breaks when Escape is pressed:

    while(true)
    {
        cki = Console.ReadKey();
        if (cki.Key == ConsoleKey.Escape)
           break;
    
        stuffs.Add(cki.Key.ToString());
        Console.WriteLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that reads of a global config file using Config::Tiny. Based
I have a tiny little program in Java which supposed to display 2 spheres.
I have 3 tiny files which I use to make a static library and
i have a tiny JS problem: If a user visits a special site http://www.test.de
I have this tiny Qt project with a project file like this: TEMPLATE =
I have a tiny (rikiki) problem in SWT ... I am making a small
Suppose I have: Toby Tiny Tory Tily Is there an algorithm that can easily
So I have a tiny header image that repeats on the x axis, but
I'm writing a simple app that's going to have a tiny form sitting in
I have coded my own tiny static DAL class for .NET Compact Framework and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.