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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:36:49+00:00 2026-05-13T05:36:49+00:00

what i want to do is that when people using my program hit enter

  • 0

what i want to do is that when people using my program hit enter without anything in there it does not cause an error here is part of the program:

Console.WriteLine("4.-Ya no quiero jugar >.<");
int opc = Convert.ToInt16(Console.ReadLine());

switch (opc)
{
    case 1:
        Console.WriteLine("omg");
        break;

    case 2:
        Console.WriteLine("wtf");
        break;

    default:
        Console.WriteLine("Cant do that  >.>");
        Console.ReadKey();
        break;

    etc.
}

the thing is im using integers,i tried to do this

string opc1=console.readline();

if (opc =="")
{
    console.writeline("nope,try again");
}
else
{ // Brace was omitted in original - Jon
    int opc = Convert.ToInt16(Console.ReadLine());

    switch (opc)

    blah blah.

and different combinations of it >.< and default does not work for that

i hope some one can help me solve it >.<

  • 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-13T05:36:49+00:00Added an answer on May 13, 2026 at 5:36 am

    First, Set your Console.ReadLine() to a variable.
    Then check to see if the variable you set is not empty or null. Also, I’d recommend using the TryParse method of the Int16 class because it returns true or false depending on if the conversion was successful.

    Also, you don’t need to convert your ReadLine to an integer, because you can switch on Strings also. Since ReadLine is already a String, no conversion is necessary. However, if you need integers, try this:

    String lineIn = Console.ReadLine();
    
    if (!String.IsNullOrEmpty(lineIn))
    {
        Int16 myNum;
        if (Int16.TryParse(lineIn , out myNum))
        {
                switch(myNum)
                {
                        case 1:
                        ...
                        default:
                        ...
                }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To let people know what version of the program they are using, i want
Assume that i have written a program in C++ without using RTTI and run-time
I have a desktop written with Winforms. Now I have requests that people want
I want to keep logs of some things that people do in my app,
I want a permission that will prevent people from logging in. (So, all users
i want to make a php app that let people submit photos/videos/sounds Now, everything
I have created an iframe code that I want people to use as a
Many languages have standard repositories where people donate useful libraries that they want others
I want to construct a transact sql script that will stop specified people from
I want to have a User Control that takes a collection of People (property

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.