I've seen examples of generic extension methods in C# for enumerations that use where T: struct, also another that uses where T: IComparable. For example, in the former case:
public static class EnumExtensionMethods
{
public static string Description<T>(this T enumValue) where T : struct
{
// ...
}
}
I'm confused why the constraint requires that type T must be a struct. I'd expect it to be where T : Enum. Can someone explain this to me? As a bonus item, maybe also explain why IComparable is also used in some examples.
FWIW, I did my research on this. I can find explanations on why IComparable is used, for example in this question, but it doesn't seem conclusive, nor do they explain why struct is used in conjunction.