<bdo id='zAkYL'></bdo><ul id='zAkYL'></ul>
<i id='zAkYL'><tr id='zAkYL'><dt id='zAkYL'><q id='zAkYL'><span id='zAkYL'><b id='zAkYL'><form id='zAkYL'><ins id='zAkYL'></ins><ul id='zAkYL'></ul><sub id='zAkYL'></sub></form><legend id='zAkYL'></legend><bdo id='zAkYL'><pre id='zAkYL'><center id='zAkYL'></center></pre></bdo></b><th id='zAkYL'></th></span></q></dt></tr></i><div id='zAkYL'><tfoot id='zAkYL'></tfoot><dl id='zAkYL'><fieldset id='zAkYL'></fieldset></dl></div>

<small id='zAkYL'></small><noframes id='zAkYL'>

    <legend id='zAkYL'><style id='zAkYL'><dir id='zAkYL'><q id='zAkYL'></q></dir></style></legend>

    1. <tfoot id='zAkYL'></tfoot>

        事件和委托及其各自应用程序之间的区别

        Difference between events and delegates and its respective applications(事件和委托及其各自应用程序之间的区别)

            <tbody id='syjXk'></tbody>
            <legend id='syjXk'><style id='syjXk'><dir id='syjXk'><q id='syjXk'></q></dir></style></legend>

              <bdo id='syjXk'></bdo><ul id='syjXk'></ul>

              • <tfoot id='syjXk'></tfoot>

                <small id='syjXk'></small><noframes id='syjXk'>

                <i id='syjXk'><tr id='syjXk'><dt id='syjXk'><q id='syjXk'><span id='syjXk'><b id='syjXk'><form id='syjXk'><ins id='syjXk'></ins><ul id='syjXk'></ul><sub id='syjXk'></sub></form><legend id='syjXk'></legend><bdo id='syjXk'><pre id='syjXk'><center id='syjXk'></center></pre></bdo></b><th id='syjXk'></th></span></q></dt></tr></i><div id='syjXk'><tfoot id='syjXk'></tfoot><dl id='syjXk'><fieldset id='syjXk'></fieldset></dl></div>

                  本文介绍了事件和委托及其各自应用程序之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  除了作为语法糖之外,我没有看到使用事件相对于委托的优势.也许我理解错了,但似乎事件只是代表的占位符.

                  I don't see advantages of using events over delegates, other than being syntactical sugar. Perhaps I am misunderstanding, but it seems that event is just a placeholder for delegate.

                  您能向我解释一下这些区别以及何时使用哪个?有什么优点和缺点?我们的代码深深植根于事件,我想深入了解它.

                  Would you explain to me the differences and when to use which? What are the advantages and disadvantages? Our code is heavily rooted with events, and I want to get to the bottom of it.

                  您何时会在事件上使用委托,反之亦然?请在生产代码中说明您对两者的真实体验.

                  When would you use delegates over events and vice versa? Please state your real world experience with both, say in the production code.

                  推荐答案

                  从技术角度来看,其他答案已经解决了这些差异.

                  From the technical standpoint, other answers have addressed the differences.

                  从语义的角度来看,事件是对象在满足某些条件时引发的动作.例如,我的 Stock 类有一个名为 Limit 的属性,当股票价格达到 Limit 时它会引发一个事件.此通知是通过事件完成的.是否有人真正关心这个事件并订阅它超出了所有者类的关注.

                  From a semantics perspective, events are actions raised by an object when certain conditions are met. For example, my Stock class has a property called Limit, and it raises an event when the stock prices reaches the Limit. This notification is done via an event. Whether anyone actually cares about this event and subscribes to it is beyond the concern of the owner class.

                  委托是一个更通用的术语,用于描述类似于 C/C++ 术语中的指针的构造..Net 中的所有代表都是多播代表.从语义的角度来看,它们通常用作一种输入.特别是,它们是实现策略模式的完美方式.例如,如果我想对一个对象列表进行排序,我可以为该方法提供一个 Comparator 策略来告诉实现如何比较两个对象.

                  A delegate is a more generic term to describe a construct similar to a pointer in C/C++ terms. All delegates in .Net are multicast delegates. From a semantics perspective, they are generally used as a kind of input. In particular, they are a perfect way to implement the Strategy Pattern. For example, if I want to sort a List of objects, I can provide a Comparator strategy to the method to tell the implementation how to compare two objects.

                  我在生产代码中使用了这两种方法.当满足某些属性时,我的大量数据对象会发出通知.最基本的示例,每当属性更改时,都会引发 PropertyChanged 事件(请参阅 INotifyPropertyChanged 接口).我在代码中使用了委托来提供将某些对象转换为字符串的不同策略.这个特定示例是一个美化的 ToString() 实现列表,用于特定对象类型以将其显示给用户.

                  I have used the two methods in production code. Tons of my data objects notify when certain properties are met. Most basic example, whenever a property changes, a PropertyChanged event is raised (see INotifyPropertyChanged interface). I have used delegates in code to provide different strategies of turning certain objects into string. This particular example was a glorified ToString() list of implementations for a particular object type to display it to users.

                  这篇关于事件和委托及其各自应用程序之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  • <i id='fuUEK'><tr id='fuUEK'><dt id='fuUEK'><q id='fuUEK'><span id='fuUEK'><b id='fuUEK'><form id='fuUEK'><ins id='fuUEK'></ins><ul id='fuUEK'></ul><sub id='fuUEK'></sub></form><legend id='fuUEK'></legend><bdo id='fuUEK'><pre id='fuUEK'><center id='fuUEK'></center></pre></bdo></b><th id='fuUEK'></th></span></q></dt></tr></i><div id='fuUEK'><tfoot id='fuUEK'></tfoot><dl id='fuUEK'><fieldset id='fuUEK'></fieldset></dl></div>
                      <tbody id='fuUEK'></tbody>

                    • <small id='fuUEK'></small><noframes id='fuUEK'>

                      <tfoot id='fuUEK'></tfoot>
                      <legend id='fuUEK'><style id='fuUEK'><dir id='fuUEK'><q id='fuUEK'></q></dir></style></legend>

                          <bdo id='fuUEK'></bdo><ul id='fuUEK'></ul>