为什么你需要在C#中的部分方法?可以事件被用于实现同样的目标?目标、事件、部分、方法

由网友(浪战)分享简介:我在读这本书A preSS临LINQ的:语言集成查询在C#,我碰到局部的方法,但我真的不明白什么是需要他们。I was reading the book "Apress Pro LINQ: Language Integrated Query in C#" and I came across partial metho...

我在读这本书A preSS临LINQ的:语言集成查询在C#,我碰到局部的方法,但我真的不明白什么是需要他们。

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.

我觉得书中的例子(属性变更前后),可以使用事件实现。因此,任何的解释?

I think the examples in the book (properties before and after change) can be implemented using events. So any explanation?

推荐答案

是的,你可以实现类似与事件,你可以与部分应用效果。部分方法是真正让code发电机,主要是设计,生成挂钩的非产生code的只是一种方式。活动可以填补这个角色。

Yes, you could achieve a similar effect with events as you can with partial methods. Partial methods are really just a way of letting code generators, primarily designers, to generate hooks for the non-generated code. Events could fill this role.

不过也有优势,部分方法在具体事件

However there are advantages to partial methods over events in particular

偏方法呼叫从所生成的IL完全去除,如果没有实施。这不能与事件完成。 的局部方法的设计是要解决的问题,其中有1提供者的钩和1消费者。事件是为了建模1提供商与N-消费者和有附带了这样的设计的开销 有没有问题排序(谁先走)。随着事件,你需要确保code的订阅事件运行之前设计器生成code引发事件。如果说设计者产生构造,这并不总是可能的。分部方法有没有这样的问题。
阅读全文

相关推荐

最新文章