using System.ComponentModel.DataAnnotations;
[Display(Name="This is monthly")]
[Display(Name="This is monthly in advance")]
SixMonthlyInArrears = -6,
public static void Main()
Console.WriteLine(((BillingCycle)(-1)).GetDisplayName());
Console.WriteLine(((BillingCycle)1).GetDisplayName());
Console.WriteLine(((BillingCycle)6).GetDisplayName());
Console.WriteLine(((BillingCycle)100).GetDisplayName());
public static class EnumExtensions
public static string GetDisplayName(this Enum value)
var type = value.GetType();
throw new ArgumentException($"Type '{type}' is not Enum");
var members = type.GetMember(value.ToString());
throw new ArgumentException($"Member '{value}' not found in type '{type.Name}'");
var attributes = member.GetCustomAttributes(typeof(DisplayAttribute), false);
if (attributes.Length == 0 || string.IsNullOrEmpty(((DisplayAttribute)attributes[0]).GetName()))
var attribute = (DisplayAttribute)attributes[0];
return attribute.GetName()!;