Why you need partial methods in c#? Can events be used to achieve the same goal?

后端 未结 4 1692
南笙
南笙 2021-01-04 08:48

I was reading the book \"Apress Pro LINQ: Language Integrated Query in C#\" and I came across partial methods, but I really don\'t understand what is the need for them.

4条回答
  •  别那么骄傲
    2021-01-04 09:33

    The compiler will remove calls to partial methods if there are no implementations. With the alternative of events, listeners would have to be checked at runtime (they would also need to be stored, etc). This allows partial methods to be more performant, especially when there are many of potential "events" and only a few have "listeners" registered.

提交回复
热议问题