开发者

Can we make a enum as a generic data type?

开发者 https://www.devze.com 2022-12-18 04:05 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消