C# setting case constant expressions, do they have to follow a specific order?

Posted by Umeed on Stack Overflow See other posts from Stack Overflow or by Umeed
Published on 2013-11-11T03:45:11Z Indexed on 2013/11/11 3:53 UTC
Read the original article Hit count: 102

Filed under:
|

Say I'm making a simple program, and the user is in the menu.

And the menu options are 1 3 5 7 (i wouldn't actually do that but lets just go with it).

and I want to make my switch statement

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DecisionMaking2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please choose an option: ");
            string SelectedOpt = Console.ReadLine();
            double Selection = Convert.ToDouble(SelectedOpt);

            double MenuOption = (Selection);

            switch (MenuOption)
            {
                case 1:
                    Console.WriteLine("Selected option #1");
                    break;
                case 2:
                    Console.WriteLine("Selected option #3");
                    break;
                case 3:
                    Console.WriteLine("Selected option #5");
                    break;
                case 4:
                    Console.WriteLine("Selected option #7");
                    break;
                default:
                    Console.WriteLine("Please choose from the options List!");
                    break;
            }
        }
    }
}

would that work? or would I have to name each case constant expression the option number I am using?

I went to the microsoft website and I didn't quite pick up on anything i was looking for. .

Also while I have your attention, how would I make it so the user chooses from either option and because I don't know which option the user will select " double MenuOption = " could be anything, whatever the user inputs right? so would what I have even work?

I am doing this all by hand, and don't get much lab time to work on this as I have tons of other courses to work on and then a boring job to go to, and my PC at home has a restarting issue lol.

soo any and all help is greatly appreciated.

p.s the computer I'm on right now posting this, doesn't have any compilers, coding programs, and it's not mine just to get that out of the way.

Thanks again!

© Stack Overflow or respective owner

Related posts about c#

Related posts about switch-statement