Answers for "enum c# get value from name"

C#
1

Get the value of an Enum c#

public enum Vehicle: byte
{
    Car,
    Bike=3,
    Truck,
    Taxi,
}

Console.WriteLine((int)VehicleEnum.Car);
string vehicle = Vehicle.Bike.ToString();
Console.WriteLine(vehicle);

Output:
0
Bike
Posted by: Guest on November-03-2021
1

c# get enum name from value

string name=(weekdays)2;//returns weekdays which has value 2.Here weekdays is enum name
Posted by: Guest on March-03-2021

C# Answers by Framework

Browse Popular Code Answers by Language