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

后端 未结 4 490
感动是毒
感动是毒 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条回答
  •  旧时难觅i
    2020-12-24 05:47

    ValueType is not the base class of value types, it is simply a container for the value when it is boxed. Since it is a container class and not in any sort of hierarchy for the actual types you're wanting to use, it is not useful as a generic constraint.

提交回复
热议问题