Search code examples
c#genericstype-conversiontype-constraints

What are Conversion Type Constraints in C# (Term used in C# in Depth 3rd edition)


I'm reading through the generics section currently and have come across a section titled "Conversion Type Constraints". I couldn't get my head around Jon's explanation so I typed the term into Google to find no results that use this exact phrase nor explain it in more detail.

Does anyone have any websites/pages which describe "Conversion Type Constraints" in more detail? Or perhaps someone knows of a more widely used term to describe them?

The description given is: A constraint that lets you specify another type that the type argument must be implicitly convertible to via an identity, reference or boxing conversion


Solution

  • Yes, this isn't an official term - as far as I can tell, there is no one official term for the three similar constraints listed as class-type, interface-type or type-parameter in the constructions shown in section 10.1.5 of the C# specification.

    It's a shame there isn't an official term for this set of constraints, as they're clearly closely related - they're all used to constrain the type argument such that there is a reference conversion or identity conversion from the type argument to the specified constraint type.