c# switch case enum

enum Menu
        {
            Students_Detail = 1,
            Display = 2,
            Exit = 3
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Please select a menu option");
            Console.WriteLine("1. Students Detail");
            Console.WriteLine("2. Display");
            Console.WriteLine("3. Exit");
            int pick = Convert.ToInt32(Console.ReadLine());
            Menu menuChoice = new Menu();
            menuChoice = (Menu)pick;

            switch (pick)
            {
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                default:
                    break;
            }
        }

3.44
9
Jay2006 110 points

                                    enum Country { Spain, USA, Japan };
static void Main(string[] args)
{
    Country country;
    Console.WriteLine("Enter the number of country\n 1.Spain \n 2.The USA \n 3.Japan");
    string input = Console.ReadLine();
    bool sucess = Enum.TryParse<Country>(input, out country);

    if (!sucess)
    {
        Console.WriteLine("entry {0} is not a valid country", input);
        return;
    }

    switch (country)
    {
        case Country.Spain:
            Console.WriteLine("Its in Europe");
            break;
        case Country.USA:
            Console.WriteLine("Its in North America");
            break;
        case Country.Japan:
            Console.WriteLine("Its in Asia");
            break;
    }
    Console.ReadKey();
}

public static RGBColor FromRainbow(Rainbow colorBand) =>
    colorBand switch
    {
        Rainbow.Red    => new RGBColor(0xFF, 0x00, 0x00),
        Rainbow.Orange => new RGBColor(0xFF, 0x7F, 0x00),
        Rainbow.Yellow => new RGBColor(0xFF, 0xFF, 0x00),
        Rainbow.Green  => new RGBColor(0x00, 0xFF, 0x00),
        Rainbow.Blue   => new RGBColor(0x00, 0x00, 0xFF),
        Rainbow.Indigo => new RGBColor(0x4B, 0x00, 0x82),
        Rainbow.Violet => new RGBColor(0x94, 0x00, 0xD3),
        _              => throw new ArgumentException(message: "invalid enum value", paramName: nameof(colorBand)),
    };


public static RGBColor FromRainbowClassic(Rainbow colorBand)
{
    switch (colorBand)
    {
        case Rainbow.Red:
            return new RGBColor(0xFF, 0x00, 0x00);
        case Rainbow.Orange:
            return new RGBColor(0xFF, 0x7F, 0x00);
        case Rainbow.Yellow:
            return new RGBColor(0xFF, 0xFF, 0x00);
        case Rainbow.Green:
            return new RGBColor(0x00, 0xFF, 0x00);
        case Rainbow.Blue:
            return new RGBColor(0x00, 0x00, 0xFF);
        case Rainbow.Indigo:
            return new RGBColor(0x4B, 0x00, 0x82);
        case Rainbow.Violet:
            return new RGBColor(0x94, 0x00, 0xD3);
        default:
            throw new ArgumentException(message: "invalid enum value", paramName: nameof(colorBand));
    };
}

3.44 (9 Votes)
0
4.25
8
Aliciahsteen 105 points

                                    public enum Operator
{
    PLUS, MINUS, MULTIPLY, DIVIDE
}


switch(op)
{
     case Operator.PLUS:
     {
        // your code 
        // for plus operator
        break;
     }
     case Operator.MULTIPLY:
     {
        // your code 
        // for MULTIPLY operator
        break;
     }
     default: break;
}

4.25 (8 Votes)
0
5
1

                                    public class Example
{
  // Button click event
  public void Click(object sender, RoutedEventArgs e)
  {
            if (sender is Button handler)
            {
                switch (handler.Tag.ToString())
                {
                  case string tag when tag.StartsWith("Example"):
                       // your code
                    break;
                    
                  default:
                    break;
                }
            }
  }
}

5 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
c# switch case enum string case switch enum c# switch case inside switch case c# switch case enum value c# switch statement with enum c# C# enum case statement c# switch expression enum using an enum in switch case c# case statments c# c# switch statements c# switch with enum class c# case statment case contain c# switch c# enum in switch statement how to make a switch case loop c# swithc case c# switch statement with enums c# c# generate switch statement for enum case > c# case ">=": c# switch case in c# core c# swithc case c# case enum enum example in switch in c# c# switch expression case statement in c# swich case c# select case in c# do a switch using enum c# c# wswitch case c# case switch swtich case in c# 10 c# enum string in switch case wswitch case c# case c# example how to use swich case in c# switch with string case in c# switch case with enum c# int value using switch with enum in c# making a menu using switch with enum in c# best way using enum switch c# using enum switch c# switch case on enum c# c# example learn enum switch c# example enum switch c# simple switch enum example which case c# Using enum in switch statements C# switch case in csharp how to use switch case to select enum in c# switch case when c# 7 switch case types c# enums in switch case java c# switch case with enums c# switch case with enum c# <= switch case with enum c# case when c# call switch case method from enum c# case statement in c#.net switch case char c# c# case statement c# types switch case swithc case is statement in c# function case c# ? use enum with switch case c# How to Apply Swithch Case in C# c# case <= case in c# switch case c# default enum string in switch case c# switch case based on enum c# c#enum switch case c# enum in switch case c# case statement enum get enum type in switch case c# switch case in c# switch case expression c# default case switch c# c# switch case or c# case switch enum case switch c# case statements c# how to use enum in switch case c# in main C# switch case default c# switch syntax switch case statemtn with interface c# how to add an or statement to switch case in c# case statement c# c# switch case with enum switch case enum in c# c# string switch case .NET switch case switch case for enum check c# switch case c# c# switch case condition how to use enum in switch case c# C# swithc case function c# case use enum in switch case c# c# enum switch case case C# csharp switch case C# how to case c# switch case for string switch case using enums C# case state c# c# switch case contains C# case using enum property using enums in switch case c# c# switch example for enum switch case in C# with enum switch case for one enum type return another c# enum switch case c# switch case enum c# c# enumerate switch switch case c# string c# switch case enum enumeration c# with swithc switch statement c# switch case c# operator switch case or condition c# switch case c# enum inheritance switch case c# switch using enum c# csharp swithc enum c# swtich using enums how to use enums in switch case to return c# how to switch enum if statement is true c# c# switch case typeof how to use swtich statement to switch between enums c# enum switch menu c# c# switch case tricks c# switch statement c# case switch default c# switch case conditional xamarin switch case switch case syntax c# switch case payment provider c# swithc case in c# switch command c# switch statements c# switch sedezimal eingabe c sharp C# end case c# float array switch case -site:pinterest.* c# switch case type c# swich case statements in c# switch statement c# syntax c# switch default case switch case c# example c# switch case
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source