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 9083595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:48:42+00:00 2026-06-16T20:48:42+00:00

this is a beginner type question, and I am sorry for my poor English.

  • 0

this is a beginner type question, and I am sorry for my poor English.

here is the program:

using System;
public class BoolTest 
{
    static void Main() 
    {
        Console.Write("Enter a character: "); 
        char c = (char)Console.Read();
        if (Char.IsLetter(c))
        {
            if (Char.IsLower(c))
            {
                Console.WriteLine("The character is lowercase.");
            }
            else
            {
                Console.WriteLine("The character is uppercase.");
            }
        }
        else
        {
            Console.WriteLine("Not an alphabetic character.");
        }
    }
}

MSDN output is:

Enter a character: X

The character is uppercase.

Additional sample runs might look as follow:

Enter a character: x

The character is lowercase.

Enter a character: 2

The character is not an alphabetic character.

my output doesn’t say anything for this version of code. If I added a while(1==1) line before the if statement, I take three line output like:

Enter a character: X

The character is uppercase.

The character is not an alphabetic character.

The character is not an alphabetic character.

Enter a character: x

The character is lowercase.

The character is not an alphabetic character.

The character is not an alphabetic character.

Enter a character: 2

The character is not an alphabetic character.

The character is not an alphabetic character.

The character is not an alphabetic character.

I tried Console.ReadLine() end of the else statement but does not work. Also I tested comment the else blocks with while (1==1), I get only 1 output line..

I am wondering why the output is including 3 lines for me for the same sample code ?

  • 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-06-16T20:48:43+00:00Added an answer on June 16, 2026 at 8:48 pm

    My first answer was wrong – Console.Read() blocks. You probably just missed the output when running the program from Visual Studio because the window closes immediately. Just append Console.ReadLine(); twice at the end of the program to keep the window open. The first Console.ReadLine(); will consume the return you pressed after the character, the second one will wait until you press return again and therefore keep the window open.

    Or slightly modify the program to use Console.ReadKey() – use

    var c = Console.ReadKey().KeyChar;
    
    // Insert a line break to get the output on a new line.
    Console.WriteLine();
    

    and add a single Console.ReadLine(); at the end of the program. Console.ReadKey() will not block until you hit return and therefore there is no need to consume the new line with a second Console.ReadLine();.

    Original answer

    Console.Read() does not block and will immediately return -1 if no character is available. You could just insert

    while (!Console.KeyAvailable) { }
    

    right before

     char c = (char)Console.Read();
    

    to wait until a character is available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for asking such a beginner question but I can't figure this out. I
This is a beginner's question. I created a project called fileupload using pylons. I
I have a class like this public class BonusImageHandler { private static IStorageProvider _storageProvider;
Here is a beginner question on Unicode. I'm using Embarcadero C++ Builder 2009, where
I am a beginner for C++ so I'm sorry if this question sounds stupid..
I am a beginner for programming, so I am sorry if this question sounds
Please help this beginner here... I have a SQL Server 2008 R2 running on
This is a beginner-best-practice question in perl. I'm new to this language. The question
This is a beginner level question for asp.net MVC I have the following code
I believe this is a beginner's CSS question. I am utilizing the method described

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.