Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What interfaces do C# enums implement by default

Basically, if I declare an enum in C#, what interfaces does it implement by default?

public enum Group
{
    Unknown,
    Children,
    Teens,
    YoungAdults,
    Adults,
}
like image 356
michael Avatar asked Nov 20 '12 13:11

michael


1 Answers

Why not find out with a simple program?

foreach(var interfaceType in typeof(Group).GetInterfaces())
{
   Console.WriteLine(interfaceType);
}

Output:

System.IComparable
System.IFormattable
System.IConvertible

FYI, all of these come from the enum base type System.Enum, which has the following declaration according to MSDN:

[SerializableAttribute]
[ComVisibleAttribute(true)]
public abstract class Enum : ValueType, 
    IComparable, IFormattable, IConvertible
like image 56
Ani Avatar answered Nov 02 '22 23:11

Ani