Why enumeration types in generic constraints are not unmanaged
and struct
?
#3975
-
Hello everyone. I found the documentation for unmanaged types. The documentation said that the enumeration types are also be unmanaged types. However, when I use generic constraint, I cannot use If and only if I wrote the both constraint void F<TEnum>(TEnum a) where TEnum : unmanaged, Enum
{
// ...
} In addtion, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
System.Enum
is a weird beast in the runtime. Even though it is the "base type" for all enums as far as the type system is concerned it is technically a reference type. That's why you must combine it with thestruct
(orunmanaged
) constraint which eliminatesSystem.Enum
itself as being used as the generic type argument.