Why can't I use System.ValueType as a generics constraint?

后端 未结 4 511
感动是毒
感动是毒 2020-12-24 05:18
  • Why can\'t I use a constraint of where T : System.ValueType?
  • Why does Microsoft prevent this type from being a constraint?

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 05:32

    Using struct as a generic constraint is functionally equivalent to a "ValueType" constraint. In .NET, a struct is a value type.

提交回复
热议问题