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
2010-01-28 09:48:52
The example given is great and maps what i was looking for. Thanks !
HotTester
2010-01-29 04:40:36
+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
2010-01-28 09:49:13
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
2010-01-28 09:50:29