Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# .net core convert int to enum

if (Enum.IsDefined(typeof(YourEnum), yourInt))
{
    return (YourEnum) yourInt;
}

  OR:

if (Enum.IsDefined(typeof(YourEnum), yourInt))
{
    return (YourEnum) Enum.ToObject(typeof(YourEnum), yourInt);
}
Comment

c# convert string to enum value

using System;

Enum.tryParse("input", out EnumName myEnum);
Comment

c# convert string to enum

MyEnum enumValue = Enum.Parse<MyEnum>(stringValue);
Comment

C# .net core convert string to enum

var foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
if (Enum.IsDefined(typeof(YourEnum), foo))
{
    return foo;
}
Comment

Convert string to Enum using C#

/// 09/14/2022 Mahesh Kumar Yadav. <br/>
/// <summary>
/// Convert string to enum
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static T ToEnum<T>(this string value)
{
    return (T)Enum.Parse(typeof(T), value, true);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: merge sort in c# 
Csharp :: all month in array 
Csharp :: c# get last item in list 
Csharp :: convert ienumerable to list 
Csharp :: c# mailmessage set sender name 
Csharp :: linq distinct count 
Csharp :: Razor foreach loop 
Csharp :: prevent page refresh 
Csharp :: get random color 32 
Csharp :: c# dictionary initializer 
Csharp :: visual studio fix formatting 
Csharp :: unity topdown 
Csharp :: remove comma from string c# 
Csharp :: c# multiply string 
Csharp :: make a list c# 
Csharp :: razor confirm password validation 
Csharp :: c# get command line arguments 
Csharp :: send type as argument c# 
Csharp :: asp.net data annotations double 
Csharp :: google sheet script change text color 
Csharp :: get last element in a list vb.net 
Csharp :: get type of variable c# 
Csharp :: movetowards unity 
Csharp :: create sequence of squares in c# 
Csharp :: c# date format 
Csharp :: joystock movement 
Csharp :: wpf app how to get all elements 
Csharp :: coroutine start unity 
Csharp :: instantiate unity 2d in parent 
Csharp :: Task.FromResult(null) 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =