久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='vLL1O'></bdo><ul id='vLL1O'></ul>

  • <legend id='vLL1O'><style id='vLL1O'><dir id='vLL1O'><q id='vLL1O'></q></dir></style></legend>
    1. <small id='vLL1O'></small><noframes id='vLL1O'>

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

        Java 或 C# 中的事件/委托

        Events/Delegates In Java or C#(Java 或 C# 中的事件/委托)
          <tbody id='peukq'></tbody>
        • <i id='peukq'><tr id='peukq'><dt id='peukq'><q id='peukq'><span id='peukq'><b id='peukq'><form id='peukq'><ins id='peukq'></ins><ul id='peukq'></ul><sub id='peukq'></sub></form><legend id='peukq'></legend><bdo id='peukq'><pre id='peukq'><center id='peukq'></center></pre></bdo></b><th id='peukq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='peukq'><tfoot id='peukq'></tfoot><dl id='peukq'><fieldset id='peukq'></fieldset></dl></div>
        • <tfoot id='peukq'></tfoot>
            <bdo id='peukq'></bdo><ul id='peukq'></ul>
            <legend id='peukq'><style id='peukq'><dir id='peukq'><q id='peukq'></q></dir></style></legend>

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

                1. 本文介紹了Java 或 C# 中的事件/委托的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我一直在嘗試了解事件/代表,但對兩者之間的關(guān)系感到困惑.我知道委托允許您調(diào)用不同的函數(shù),而無需知道正在調(diào)用的特定函數(shù).(例如:一個繪圖函數(shù)需要接受不同函數(shù)的輸入).

                  I've been trying to learn about events/delegates, but am confused about the relationship between the two. I know that delegates allow you to invoke different functions without needing to know what particular function is being invoked. (eg: a graphing function needs to accept inputs that are different functions to be graphed).

                  但我看不到事件中如何使用委托.

                  But I don't see how delegates are used in Events.

                  有人可以構(gòu)建一個簡單的示例(在偽代碼、C# 或 Java 中)來說明與事件相關(guān)的委托的工作原理嗎?

                  Can someone construct a simple example (in pseudocode or C# or Java) that illustrates the workings of Delegates as related to Events?

                  謝謝!

                  推薦答案

                  (這都是從 C# 的角度來看的.)

                  (This is all from a C# perspective.)

                  我有一篇關(guān)于事件和委托之間區(qū)別的文章.這更詳細(xì)地涵蓋了下面提到的所有內(nèi)容.

                  I have an article about the differences between events and delegates. That covers everything mentioned below in a lot more detail.

                  基本上,我喜歡將事件視為一個屬性——它是一對方法,僅此而已.一個事件不是 get/set,而是 add/remove——意思是添加這個事件處理程序"和刪除這個事件處理程序".從本質(zhì)上講,這就是一個事件.

                  Basically I like to think of an event as being like a property - it's a pair of methods, that's all. Instead of get/set, an event has add/remove - meaning "add this event handler" and "remove this event handler". At the core, that's all an event is.

                  C# 也有 field-like events 這是一個快捷方式:

                  C# also has field-like events which are a shortcut:

                   public event EventHandler Foo;
                  

                  聲明一個字段一個事件,幾乎是微不足道的添加/刪除實現(xiàn).在類中,引用 Foo 是指字段.在類之外,引用 Foo 是指事件.

                  declares both a field and an event, with a nearly trivial add/remove implementation. Within the class, referring to Foo refers to the field. Outside the class, referring to Foo refers to the event.

                  基本思想是事件允許其他代碼訂閱和取消訂閱,方法是傳入一個委托(事件處理程序).通常,訂閱是通過創(chuàng)建一個新的多播委托來實現(xiàn)的,該委托包含上一個事件處理程序列表和新的.因此,如果您將事件處理程序存儲在名為 myEventHandlers 的字段中,訂閱實現(xiàn)可能是:

                  The basic idea is that an event allows other code to subscribe to and unsubscribe from it, by passing in a delegate (the event handler). Usually, subscription is implemented by creating a new multicast delegate containing the previous list of event handlers and the new one. So if you're storing the event handlers in a field called myEventHandlers, the subscription implementation might be:

                  myEventHandlers += value;
                  

                  類似地取消訂閱通常涉及創(chuàng)建一個新的多播委托沒有指定的處理程序:

                  Similarly unsubscription usually involves creating a new multicast delegate without the specified handler:

                  myEventHandlers -= value;
                  

                  然后,當(dāng)您想要引發(fā)/觸發(fā)事件時,您只需調(diào)用該多播委托 - 通常使用無效檢查以避免在沒有人訂閱時引發(fā)異常:

                  Then when you want to raise/fire the event, you just call that multicast delegate - usually with a nullity check to avoid an exception being thrown if no-one has subscribed:

                  EventHandler handler = myEventHandlers;
                  if (handler != null)
                  {
                      // You could pass in a different "sender" and "args" of course
                      handler(this, EventArgs.Empty);
                  }
                  

                  使用事件,訂閱者彼此不了解,并且不能自己引發(fā)事件(通常).換句話說,它是一種封裝模式,在語言和平臺中都被賦予了地位.

                  Using events, the subscribers don't know about each other, and can't raise the event themselves (usually). In other words, it's a pattern of encapsulation, which has been given status within both the language and the platform.

                  這篇關(guān)于Java 或 C# 中的事件/委托的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數(shù)溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關(guān)系嗎?)
                  How to convert Integer to int?(如何將整數(shù)轉(zhuǎn)換為整數(shù)?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內(nèi)創(chuàng)建一個隨機(jī)打亂數(shù)字的 int 數(shù)組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠?qū)?0xff000000 存儲為 int?)
                  • <tfoot id='oELxO'></tfoot>

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

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

                        • <bdo id='oELxO'></bdo><ul id='oELxO'></ul>

                          <i id='oELxO'><tr id='oELxO'><dt id='oELxO'><q id='oELxO'><span id='oELxO'><b id='oELxO'><form id='oELxO'><ins id='oELxO'></ins><ul id='oELxO'></ul><sub id='oELxO'></sub></form><legend id='oELxO'></legend><bdo id='oELxO'><pre id='oELxO'><center id='oELxO'></center></pre></bdo></b><th id='oELxO'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oELxO'><tfoot id='oELxO'></tfoot><dl id='oELxO'><fieldset id='oELxO'></fieldset></dl></div>
                            <tbody id='oELxO'></tbody>
                          1. 主站蜘蛛池模板: 日韩在线一区二区 | 99久久中文字幕三级久久日本 | 中文在线视频 | 久久精品国产免费看久久精品 | 黄色一级毛片免费看 | 日韩中文字幕一区二区三区 | 国产一级特黄aaa大片评分 | www.午夜 | 国产亚洲精品久久久久动 | 国产日产精品一区二区三区四区 | 免费看片在线播放 | 亚洲91av| 99在线视频观看 | 91精品国产综合久久婷婷香蕉 | 久久一区二区av | 久久一区精品 | 天天综合网7799精品 | 国产一区二区三区免费 | 在线观看视频你懂得 | 国精日本亚洲欧州国产中文久久 | 亚洲精品v | 久久九九99| 狠狠婷婷综合久久久久久妖精 | www.日本精品 | 欧美日韩淫片 | 亚洲vs天堂 | 一级片成人 | 亚洲高清中文字幕 | 欧美日韩国产精品一区 | 北条麻妃视频在线观看 | 国产精品av久久久久久毛片 | 久久一起草 | 网站黄色在线 | 精品视频一区二区 | 色综合久 | 亚洲一区二区久久 | 午夜不卡一区二区 | 国产欧美精品一区二区三区 | 亚洲综合视频 | 91精品国产91久久久久久最新 | 午夜精品久久久久久久久久久久久 |