Switch with Enum and call its ToString function in CSharp

Description

The following code shows how to switch with Enum and call its ToString function.

Example


using System;/*from  w  ww. j  a v a 2  s.c  o  m*/

enum EmpType : byte {
    Manager = 10,
    Grunt = 1,
    Contractor = 100,
    VP = 9
}

class Program {
    public static void AskForBonus(EmpType e) {
        switch (e) {
            case EmpType.Contractor:
                Console.WriteLine("1");
                break;
            case EmpType.Grunt:
                Console.WriteLine("2");
                break;
            case EmpType.Manager:
                Console.WriteLine("3");
                break;
            case EmpType.VP:
                Console.WriteLine("4");
                break;
            default: break;
        }
    }


    static void Main(string[] args) {
        EmpType fred;
        fred = EmpType.VP;
        AskForBonus(fred);
        Console.WriteLine(fred.ToString());

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var