Can we make a enum as a generic data type?
Can we make a enum as a generic data type? If so p开发者_运维技巧lease provide an example. Thanks in advance.
Enums cannot be made generic.
From MSDN:
An enumeration is a named constant whose underlying type is any integral type
See this SO answer for an alternative.
No. Enums in C# have an integral base type (Int32 by default) but the items in it are always known at compile-time. There is simply no sensible way how generics might even fit into the concept of an enum.
You can try class enums.
You can pass an enum
as a type parameter to a generic method whose constraints allow it, but the enum
itself cannot be generic.
精彩评论