Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,707 questions

55,468 answers

573 users

How to use switch case statement with user input value in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Type a number: ");
            int n = int.Parse(Console.ReadLine());

            switch (n)
            {
                case 1:
                    Console.WriteLine("1");
                    break;
                case 2:
                    Console.WriteLine("2");
                    break;
                case 3:
                    Console.WriteLine("3");
                    break;
                case 4:
                    Console.WriteLine("4");
                    break;
                default:
                {
                    Console.WriteLine("default");
                    break;
                }
            }
        }
    }
}


/*
run:

Type a number: 2
2

*/

 



answered Dec 29, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Type a number: ");
            int n = int.Parse(Console.ReadLine());

            switch (n)
            {
                case 1:
                case 2:
                case 3:
                    Console.WriteLine("1 or 2 or 3");
                    break;
                case 4:
                    Console.WriteLine("4");
                    break;
                default:
                {
                    Console.WriteLine("default");
                    break;
                }
            }
        }
    }
}


/*
run:

Type a number: 2
1 or 2 or 3

*/

 



answered Dec 29, 2016 by avibootz

Related questions

1 answer 235 views
2 answers 293 views
3 answers 321 views
3 answers 275 views
2 answers 286 views
2 answers 262 views
...