Skip to main content
Active reading [<https://www.youtube.com/watch?v=1Dax90QyXgI&t=17m54s> <https://www.youtube.com/watch?v=1Dax90QyXgI&t=19m05s>]. Used more standard formatting.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

FollowingThe following is a slightly better extension method:

public static string ToEnumString<TEnum>(this int enumValue)  {   var enumString = enumValue.ToString();   if (Enum.IsDefined(typeof(TEnum), enumValue))   {   enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString();   }   return enumString;  } 

Following is slightly better extension method

public static string ToEnumString<TEnum>(this int enumValue)  {   var enumString = enumValue.ToString();   if (Enum.IsDefined(typeof(TEnum), enumValue))   {   enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString();   }   return enumString;  } 

The following is a slightly better extension method:

public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; } 
Rollback to Revision 1 - Edit approval overridden by post owner or moderator
Source Link
Kamran Shahid
  • 4.2k
  • 7
  • 61
  • 112

The followingFollowing is a slightly better extension method.

 public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; }  

The following is a slightly better extension method.

 public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; }  

Following is slightly better extension method

public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; } 

FollowingThe following is a slightly better extension method.

 public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; }  

Following is slightly better extension method

public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; } 

The following is a slightly better extension method.

 public static string ToEnumString<TEnum>(this int enumValue) { var enumString = enumValue.ToString(); if (Enum.IsDefined(typeof(TEnum), enumValue)) { enumString = ((TEnum) Enum.ToObject(typeof (TEnum), enumValue)).ToString(); } return enumString; }  
Source Link
Kamran Shahid
  • 4.2k
  • 7
  • 61
  • 112
Loading