Answers for "get value from Enum C#"

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
3

get enum by index c#

//Returns the enum value at the index
(EnumType)int;

//returns the string of the enum value at the index
(EnumType)int.ToString();
Posted by: Guest on May-04-2020
1

c# get enum value from string

//This example will parse a string to a Keys value
Keys key = (Keys)Enum.Parse(typeof(Keys), "Space");
//The key value will now be Keys.Space
Posted by: Guest on April-28-2020
0

c# get string value of enum

using System;

public class GetNameTest {
    enum Colors { Red, Green, Blue, Yellow };
    enum Styles { Plaid, Striped, Tartan, Corduroy };

    public static void Main() {

        Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
        Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
    }
}
// The example displays the following output:
//       The 4th value of the Colors Enum is Yellow
//       The 4th value of the Styles Enum is Corduroy
Posted by: Guest on December-15-2020
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
0

c# get value of object in enum

arrayName variable = (arrayName) index
//for example
Days day = (Days)3;
Posted by: Guest on May-17-2020

C# Answers by Framework

Browse Popular Code Answers by Language