Skip to content

generic constrains for enum #69730

Answered by CyrusNajmabadi
ali50m asked this question in General
Aug 26, 2023 · 3 comments · 5 replies
Discussion options

You must be logged in to vote

thanks for your reply. But I can`t define Foo<System.Enum> as type now.

Correct. But you asked how to use this Yoo generic. You can use the Yoo generic with the System.Enum type. You can use the Foo generic with any actual enum type.

Maybe the Foo should not have the constrains both for struct and Enum at the same time.

The Foo generic makes complete sense. It is saying that to be instantiated the type must be a subtype of System.Enum, and that it must be a struct. In .net today there are tons of types that satisfy this. Namely, every single enum.

The Yoo generic is odd, but still makes sense. It is saying that to be instantiated the type must be a subtype of System.ENum (or System.En…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@CyrusNajmabadi
Comment options

Answer selected by ali50m
@zacharylayne
Comment options

@ali50m
Comment options

@huoyaoyuan
Comment options

Comment options

You must be logged in to vote
1 reply
@CyrusNajmabadi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants