Why are delegates reference types?

前端 未结 7 618
星月不相逢
星月不相逢 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:19

    I saw this interesting conversation on the Internet:

    Immutable doesn't mean it has to be a value type. And something that is a value type is not required to be immutable. The two often go hand-in-hand, but they are not actually the same thing, and there are in fact counter-examples of each in the .NET Framework (the String class, for example).

    And the answer:

    The difference being that while immutable reference types are reasonably common and perfectly reasonable, making value types mutable is almost always a bad idea, and can result in some very confusing behaviour!

    Taken from here

    So, in my opinion the decision was made by language usability aspects, and not by compiler technological difficulties. I love nullable delegates.

    0 讨论(0)
提交回复
热议问题