79652168

Date: 2025-06-04 05:48:08
Score: 1
Natty:
Report link

I was looking for Enum to Name/Value, thanks to @Paul Rivera the `char.IsLetter((char)i)` helped me to get my result, here is my code, maybe somebody needs it:

    System.Collections.IEnumerable EnumToNameValue<T>() where T : struct, Enum
    {
        var values = Enum.GetValues<T>().Select(x => (Name: x.ToString(), Value: (int)(object)x));
        var isChar = values.All(x => char.IsLetter((char)x.Value));
        return values.Select(x => new { x.Name, Value = isChar ? (char)x.Value : (object)x.Value }).ToList();
    }
Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @the
  • Low reputation (0.5):
Posted by: Mohammadreza Askari