Why are delegates reference types?

前端 未结 7 712
星月不相逢
星月不相逢 2020-12-04 19:28

Quick note on the accepted answer: I disagree with a small part of Jeffrey\'s answer, namely the point that since Delegate had to be a referenc

7条回答
  •  执念已碎
    2020-12-04 20:00

    I guess one reason is support for multi cast delegates Multi cast delegates are more complex than simply a few fields indicating target and method.

    Another thing that's only possible in this form is delegate variance. This kind of variance requires a reference conversion between the two types.

    Interestingly F# defines it's own function pointer type that's similar to delegates, but more lightweight. But I'm not sure if it's a value or reference type.

提交回复
热议问题