Using C#, how can I take the min or max of two enum values?
For example, if I have
enum Permissions
{
None,
Read,
Write,
Full
}
is there a method that lets me do Helper.Max(Permissions.Read, Permissions.Full)
and get Permissions.Full
, for example?
An ENUM column can have a maximum of 65,535 distinct elements.
The Enum constructor can accept multiple values.
Enumeration or Enum in C is a special kind of data type defined by the user. It consists of constant integrals or integers that are given names by a user. The use of enum in C to name the integer values makes the entire program easy to learn, understand, and maintain by the same or even different programmer.
Enums implement IComparable
so you can use:
public static T Min<T>(T a, T b) where T : IComparable
{
return a.CompareTo(b) <= 0 ? a : b;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With