Delegate Conversions #7049
-
Aren't all delegates with matching parameter types supposed to be convertable to each other? If so, why is it that V1 and V2 aren't equivalent? And how are they different?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
No, delegates are nominal types and not convertible between each other regardless of their signature. The natural type for a method group will be one of the |
Beta Was this translation helpful? Give feedback.
No, delegates are nominal types and not convertible between each other regardless of their signature. The natural type for a method group will be one of the
Action<...>
orFunc<...>
delegate families if compatible, otherwise the compiler will emit a compatible delegate type with an unspeakable name. That is whyV1
contains a single method, the natural delegate type for methodTest3
isFunc<string, string, CancellationToken, IAsyncEnumerable<string>>
. But even though that delegate has the same signature asInvokeMethod1
andInvokeMethod2
it is not considered the same type and cannot be cast to th…