Answers for "get enum value c#"

C#
3

c# enum.getvalues

enum Colors { Red, Green, Blue };
enum Styles { Plaid = 0, Striped = 23, Tartan = 65 };

public static void Main() {
    foreach(int i in Enum.GetValues(typeof(Colors)))
        Console.WriteLine(i);

    foreach(int i in Enum.GetValues(typeof(Styles)))
        Console.WriteLine(i);
}

// OUTPUT:
//    0
//    1
//    2
//       
//    0
//    23
//    65
Posted by: Guest on March-21-2020
0

get enum name from value c#

int enumValue = 2; // The value for which you want to get string 
string enumName = Enum.GetName(typeof(EnumDisplayStatus), enumValue);
Posted by: Guest on April-30-2021
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
2

get enum value c#

int something = (int) Question.Role;
Posted by: Guest on March-17-2020
0

get an enum by value in C#

using System;
 
public class Example
{
    public enum Days
    {
        Monday = 1,
        Tuesday = 2,
        Wednesday = 3,
        Thursday = 4,
        Friday = 5,
        Saturday = 6,
        Sunday = 7
    }
 
    public static void Main()
    {
        int value = 5;
 
        string day = Enum.GetName(typeof(Days), value);
        Console.WriteLine(day);
    }
}
 
/*
    Output: Friday
*/
Posted by: Guest on September-19-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