Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

get enum value c#

int something = (int) Question.Role;
Comment

reflection get enum value C#

System.Type enumType = typeof(TestEnum);
System.Type enumUnderlyingType = System.Enum.GetUnderlyingType(enumType);
System.Array enumValues = System.Enum.GetValues(enumType);

for (int i=0; i < enumValues.Length; i++)
{
    // Retrieve the value of the ith enum item.
    object value = enumValues.GetValue(i);

    // Convert the value to its underlying type (int, byte, long, ...)
    object underlyingValue = System.Convert.ChangeType(value, enumUnderlyingType);

    System.Console.WriteLine(underlyingValue);
}
Comment

reflection get enum value C#

object underlyingValue = Convert.ChangeType(value, Enum.GetUnderlyingType(value.GetType()));
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# multiple exceptions same handler 
Csharp :: c# getting response content from post 
Csharp :: save binary data to file c# 
Csharp :: dbset properties 
Csharp :: how to add arrays in c# 
Csharp :: c# square symbol 
Csharp :: strong email validation regex c# 
Csharp :: c# nunit test case 
Csharp :: triangle calculator 
Csharp :: out c# 
Csharp :: binary tree c# 
Csharp :: send mail c# 
Csharp :: Reporting Progress from Async Tasks c# 
Csharp :: concurrent post request c# 
Csharp :: VBNet dictionary for each 
Csharp :: Delayed respawn timer 
Csharp :: wpf fixed window size 
Csharp :: How to cache database tables to prevent many database queries in Asp.net C# mvc 
Csharp :: decode token to get claims value 
Csharp :: MissingMethodException: PlayerManager.OnPlayerLeft Due to: Attempted to access a missing member. 
Csharp :: validate preview input number wpf 
Csharp :: how to input message ox in c# 
Csharp :: copy file image in c# 
Csharp :: 2d collision handling jump table 
Csharp :: unity mouse click 
Csharp :: convert string csv line to list c# 
Csharp :: external font family uwp c# 
Csharp :: c# text to ascii 
Csharp :: image into sql database 
Csharp :: duplicate global system runtime versioning targetframeworkattribute 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =