views:

120

answers:

4

Can we make a enum as a generic data type? If so please provide an example. Thanks in advance.

+7  A: 

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.

Oded
The example given is great and maps what i was looking for. Thanks !
HotTester
+2  A: 

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.

Joey
A: 

You can pass an enum as a type parameter to a generic method whose constraints allow it, but the enum itself cannot be generic.

Jay
+1  A: 

You can try class enums.

Arnis L.
Thanks for the link. It really is the way i wanted to solution to be ... but to be frank its a lot complicated ! Can u share a less complicated example ?
HotTester
@HotTest probably not. All that stuff is necessary.
Arnis L.