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);
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);
C# .net core convert string to enum
var foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
if (Enum.IsDefined(typeof(YourEnum), foo))
{
return foo;
}
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
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
how to pass string value to enum in c#
MyEnum myEnum = (MyEnum)Enum.Parse(typeof(MyEnum), myString);
c# get enum name from value
string name=(weekdays)2;//returns weekdays which has value 2.Here weekdays is enum name
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us