Question regarding implicit conversions in the C# language specification

前端 未结 4 856
渐次进展
渐次进展 2021-02-08 08:15

Section 6.1 Implicit conversions defines an identity conversion thusly:

An identity conversion converts from any type to the sam

4条回答
  •  离开以前
    2021-02-08 08:31

    Section 4.7 of the specification notes that there is an identity conversion from Foo to Foo and vice versa. The portion of the spec you quoted is written to ensure that this case is handled. That is, if there is an implicit reference conversion from T to C then there is also an implicit reference conversion to C, C and C.

    One might reasonably point out that (1) the intention of these phrases is unobvious - hence your question - and confusing, and (2) that the section on identity conversions ought to cross-reference the section on dynamic conversions, and (3) phrases like this in the spec make it difficult for an implementor of the specification to clearly translate the spec language into an implementation. How is one to know if any such type exists? The spec need not specify exact algorithms, but it would be nice if it gave more guidance.

    The spec is, sadly, not a perfect document.

    提交回复
    热议问题