ã€ãã³ããšã¯äœã§ããïŒ
CïŒã®ã€ãã³ãã¯ã2ã€ã®å¯èœæ§ãæäŸãããšã³ãã£ãã£ã§ãïŒã¯ã©ã¹ã«å¯ŸããŠãå€æŽãå ±åãããããããã³ãŠãŒã¶ãŒã«å¯ŸããŠããããã«å¿çããããã«ã
ã€ãã³ãçºè¡šã®äŸïŒ
public event EventHandler Changed;
åºåã®æ§æãæ€èšããŠãã ããã ã€ãã³ã修食åãæåã«æ¥ãŠã次ã«ã€ãã³ãããŒã¯ãŒããç¶ããã€ãã³ãã¿ã€ããç¶ããŸããã€ãã³ãã¿ã€ãã¯ããªã²ãŒãã¿ã€ãã§ããå¿ èŠããããã€ãã³ãèå¥åãã€ãŸããã®ååã§ãã ã€ãã³ãããŒã¯ãŒãã¯ãããããããªãã¯ãã£ãŒã«ãã§ã¯ãªããã€ãã³ãã¡ã«ããºã ã®å®è£ ã®ããã°ã©ãã®è©³çŽ°ãé ãç¹å¥ã«èšèšãããæ§é ã§ããããšãã³ã³ãã€ã©ã«äŒããŸãã ãã®ã¡ã«ããºã ãã©ã®ããã«æ©èœããããç解ããã«ã¯ã代衚è ã®ä»äºã®ååãç 究ããå¿ èŠããããŸãã
ã€ãã³ãã¯ãŒã¯ãã³ã-ããªã²ãŒã
.NETã®ããªã²ãŒãã¯ãC ++ã®é¢æ°åç §ã®äžçš®ã§ãããšèšããŸãã ãã ãããã®å®çŸ©ã¯äžæ£ç¢ºã§ãããªããªãã åããªã²ãŒãã¯1ã€ã§ã¯ãªããããªã²ãŒãã®åŒã³åºããªã¹ãã«æ ŒçŽãããŠããä»»æã®æ°ã®ã¡ãœãããåç §ã§ããŸãã ããªã²ãŒãåã¯ãåç §ã§ããã¡ãœããã®ã·ã°ããã£ãèšè¿°ããŸã;ãã®åã®ã€ã³ã¹ã¿ã³ã¹ã«ã¯ãç¬èªã®ã¡ãœãããããããã£ãããã³æŒç®åããããŸãã InvokeïŒïŒã¡ãœãããåŒã³åºããšãåãªã¹ãã¡ãœãããžã®é 次åŒã³åºããå®è¡ãããŸãã ããªã²ãŒãã¯é¢æ°ãšããŠåŒã³åºãããšãã§ããã³ã³ãã€ã©ã¯ãã®ãããªåŒã³åºããInvokeïŒïŒåŒã³åºãã«å€æããŸãã
CïŒã«ã¯ãããªã²ãŒãçšã«ã.NETç°å¢ã«ã¯ååšããªã+ããã³-æŒç®åããããããããèšèªã®æ§æç³è³ªã§ãããããããDelegate.Combineããã³Delegate.Removeã¡ãœããã®åŒã³åºãã«æ¡åŒµãããŸãã ãããã®ã¡ãœããã䜿çšãããšãåŒã³åºããªã¹ãã§ã¡ãœãããè¿œå ããã³åé€ã§ããŸãã ãã¡ãããä»£å ¥ïŒ+ =ããã³-=ïŒãæã€æŒç®åã®åœ¢åŒã¯ãä»ã®åã®.NETç°å¢ã§å®çŸ©ãããæŒç®åã ãã§ãªããããªã²ãŒãæŒç®åã«ãé©çšã§ããŸãã ããªã²ãŒãããæžç®ãããšãã«ã圌ã®åŒã³åºããªã¹ãã空ã®å Žåãnullãå²ãåœãŠãããŸãã
ç°¡åãªäŸãèããŠã¿ãŸãããã
Action a = () => Console.Write("A"); //Action public delegate void Action(); Action b = a; Action c = a + b; Action d = a - b; a(); // A b(); // A c(); // AA d(); // NullReferenceException, .. d == null
ã€ãã³ã-ããã©ã«ãã®å®è£
CïŒã®ã€ãã³ãã¯ã次ã®2ã€ã®æ¹æ³ã§å®çŸ©ã§ããŸãã
- ã€ãã³ãã®æé»çãªå®è£ ïŒãã£ãŒã«ãã®ãããªã€ãã³ãïŒã
- æ瀺çãªã€ãã³ãå®è£ ã
æãäžè¬çã«äœ¿çšãããã€ãã³ãå®è£ -æé»çãæ€èšããŠãã ããã CïŒ4ã«æ¬¡ã®ãœãŒã¹ã³ãŒãããããšä»®å®ããŸãïŒããã¯éèŠã§ãã以åã®ããŒãžã§ã³ã§ã¯ãå°ãç°ãªãã³ãŒããçæãããŸãããããã«ã€ããŠã¯åŸã§èª¬æããŸãïŒã
class Class { public event EventHandler Changed; }
ãããã®è¡ã¯ãã³ã³ãã€ã©ã«ãã£ãŠæ¬¡ã®ãããªã³ãŒãã«å€æãããŸãã
class Class { EventHandler hanged; public event EventHandler Changed { add { EventHandler eventHandler = this.changed; EventHandler comparand; do { comparand = eventHandler; eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.changed, comparand + value, comparand); } while(eventHandler != comparand); } remove { EventHandler eventHandler = this.changed; EventHandler comparand; do { comparand = eventHandler; eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.changed, comparand - value, comparand); } while (eventHandler != comparand); } } }
ã€ãã³ãã®ãµãã¹ã¯ã©ã€ãæã«addãããã¯ãåŒã³åºããããµãã¹ã¯ã©ã€ã解é€æã«removeãããã¯ãåŒã³åºãããŸãã ãããã®ãããã¯ã¯ãäžæã®ååãæã€åå¥ã®ã¡ãœããã«ã³ã³ãã€ã«ãããŸãã ãããã®ã¡ãœããã¯äž¡æ¹ãšãã1ã€ã®ãã©ã¡ãŒã¿ãŒïŒã€ãã³ãã®ã¿ã€ãã«å¯Ÿå¿ããã¿ã€ãã®ããªã²ãŒãïŒãåãåããæ»ãå€ãæã¡ãŸããã ãã©ã¡ãŒã¿åã¯åžžã«ãå€ãã§ãããã®ååã§ããŒã«ã«å€æ°ã宣èšããããšãããšãã³ã³ãã€ã«ãšã©ãŒãçºçããŸãã ã€ãã³ãããŒã¯ãŒãã®å·ŠåŽã«ç€ºãããŠããã¹ã³ãŒãã¯ããããã®ã¡ãœããã®ã¹ã³ãŒããå®çŸ©ããŸãã ããªã²ãŒãã¯ãåžžã«ãã©ã€ããŒããªã€ãã³ãã®ååã§äœæãããŸãã ãã®ãããã¯ã©ã¹ç¶æ¿ããæé»çãªæ¹æ³ã§å®è£ ãããã€ãã³ããåŒã³åºãããšã¯ã§ããŸããã
Interlocked.CompareExchangeã¯ãæåã®åŒæ°ã3çªç®ã®åŒæ°ãšæ¯èŒããçããå Žåã¯ãæåã®åŒæ°ã2çªç®ã®åŒæ°ã«çœ®ãæããŸãã ãã®ã¢ã¯ã·ã§ã³ã¯ã¹ã¬ããã»ãŒãã§ãã ã«ãŒãã¯ãããªã²ãŒããã€ãã³ãã®è¢«æ¯èŒå€æ°ã«å²ãåœãŠãåŸãæ¯èŒãå®è¡ããåã«ãå¥ã®ã¹ã¬ããããã®ããªã²ãŒããå€æŽããå Žåã«äœ¿çšãããŸãã ãã®å ŽåãInterlocked.CompareExchangeã¯çœ®ãæãããããã«ãŒãå¢çæ¡ä»¶ã¯æºããããã次ã®è©Šè¡ãè¡ãããŸãã
è¿œå ãšåé€ã®ããåºå
ã€ãã³ããæ瀺çã«å®è£ ããããšãããã°ã©ããŒã¯ã€ãã³ãã®ããªã²ãŒããã£ãŒã«ãã宣èšããadd / removeãããã¯ã䜿çšããŠãµãã¹ã¯ã©ã€ããŒãæåã§è¿œå ãŸãã¯åé€ããŸããäž¡æ¹ãšãååšããå¿ èŠããããŸãã ãã®ãããªåºåã¯ãå€ãã®å Žåãç¬èªã®ã€ãã³ãã¡ã«ããºã ãäœæããããã«äœ¿çšãããCïŒã®å©äŸ¿æ§ãç¶æããªããããããæäœããŸãã
ããšãã°ãäžè¬çãªå®è£ ã®1ã€ã¯ãã€ãã³ãããªã²ãŒãã®ãã£ã¯ã·ã§ããªãåå¥ã«æ ŒçŽããããšã§ãããã£ã¯ã·ã§ããªã«ã¯ãã€ãã³ããµãã¹ã¯ãªãã·ã§ã³ãäœæãããããªã²ãŒãã®ã¿ãå«ãŸããŸãã ãã£ã¯ã·ã§ããªã¯ãããŒã䜿çšããŠã¢ã¯ã»ã¹ãããŸããããŒã¯éåžžããªããžã§ã¯ãåã®éçãã£ãŒã«ãã§ãããåç §ã®æ¯èŒã«ã®ã¿äœ¿çšãããŸãã ããã¯ãã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãå æããã¡ã¢ãªã®éãæžããããã«è¡ãããŸãïŒå€æ°ã®ééçã€ãã³ããå«ãŸããå ŽåïŒã ãã®å®è£ ã¯ãWinFormsã§äœ¿çšãããŸãã
ã€ãã³ãã¯ã©ã®ããã«ãµãã¹ã¯ã©ã€ããããåŒã³åºãããŸããïŒ
ãã¹ãŠã®ãµãã¹ã¯ãªãã·ã§ã³ããã³ãµãã¹ã¯ã©ã€ã解é€ã¢ã¯ã·ã§ã³ïŒ+ =ããã³-=ã§ç€ºãããããªã²ãŒãæŒç®åãšæ··åãããããïŒã¯ãaddããã³removeã¡ãœããã®åŒã³åºãã«ã³ã³ãã€ã«ãããŸãã äžèšä»¥å€ã®ã¯ã©ã¹å ã®åŒã³åºãã¯ãããªã²ãŒãã䜿çšããŠåçŽãªäœæ¥ã«ã³ã³ãã€ã«ãããŸãã æé»ã®ïŒãããŠæ£ããæ瀺çãªïŒã€ãã³ãå®è£ ã§ã¯ãã¯ã©ã¹ã®å€éšããããªã²ãŒãã«ã¢ã¯ã»ã¹ããããšã¯äžå¯èœã§ããã眲åãšããŠã€ãã³ããåãæ¶ãããšã§ã®ã¿ã€ãã³ããæäœã§ããããšã«æ³šæããŠãã ããã ïŒãªãã¬ã¯ã·ã§ã³ã䜿çšããªãå ŽåïŒã€ãã³ãã«ãµãã¹ã¯ã©ã€ãããŠãããã©ãããå€æããæ¹æ³ããªãããããããããµãã¹ã¯ã©ã€ã解é€ããŠããšã©ãŒãçºçããªãããšã¯è«ççã«æããŸã-ã€ãã³ãããªã²ãŒãã空ã§ãã£ãŠããå®å šã«ãµãã¹ã¯ã©ã€ã解é€ã§ããŸãã
ã€ãã³ã修食å
ã¹ã³ãŒã修食åïŒãããªãã¯ãä¿è·ããã©ã€ããŒããå éšïŒã¯ã€ãã³ãã«äœ¿çšã§ãããªãŒããŒã©ããïŒä»®æ³ããªãŒããŒã©ã€ããã·ãŒã«ïŒããããšããå®è£ ããªãïŒæœè±¡ãå€éšïŒããšãã§ããŸãã ã€ãã³ãã¯ãåºæ¬ã¯ã©ã¹ããã®åãååã®ã€ãã³ããšéè€ããããšãïŒæ°èŠïŒããŸãã¯ã¯ã©ã¹ã®ã¡ã³ããŒã«ãªãããšãã§ããŸãïŒéçïŒã ã€ãã³ãããªãŒããŒã©ã€ã修食åãšæœè±¡ä¿®é£Ÿåã®äž¡æ¹ã§åæã«å®£èšãããå Žåãã¯ã©ã¹ã®çžç¶äººã¯ããããªãŒããŒã©ã€ãããå¿ èŠããããŸãïŒãããã®2ã€ã®ä¿®é£Ÿåãæã€ã¡ãœãããŸãã¯ããããã£ãåæ§ïŒã
ã©ããªçš®é¡ã®ã€ãã³ãããããŸããïŒ
æ¢ã«è¿°ã¹ãããã«ãã€ãã³ãã®ã¿ã€ãã¯åžžã«ããªã²ãŒãã®ã¿ã€ãã§ãªããã°ãªããŸããã ã€ãã³ãã®æšæºã¿ã€ãã¯ãEventHandlerããã³EventHandler <TEventArgs>ã¿ã€ãã§ãTEventArgsã¯EventArgsã®åå«ã§ãã EventHandleråã¯ãã€ãã³ãåŒæ°ãæäŸãããŠããªãå Žåã«äœ¿çšãããEventHandler <TEventArgs>åã¯ãã€ãã³ãåŒæ°ãããå Žåã«äœ¿çšããããããã«å¯ŸããŠåå¥ã®ã¯ã©ã¹ïŒEventArgsããã®ç¶æ¿ïŒãäœæãããŸãã ä»ã®çš®é¡ã®ããªã²ãŒãã䜿çšã§ããŸãããåæå®ãããEventHandler <TEventArgs>ã䜿çšãããšãããè«ççã§çŸããèŠããŸãã
CïŒ3ã®ãã¹ãŠã¯ã©ãã§ããïŒ
äžèšã®ãã£ãŒã«ãã®ãããªã€ãã³ãã®å®è£ ã¯ãCïŒ4èšèªïŒ.NET 4.0ïŒã«å¯Ÿå¿ããŠããŸãã 以åã®ããŒãžã§ã³ã§ã¯ãéåžžã«å€§ããªéãããããŸãã
æé»çãªå®è£ ã§ã¯ãã«ãŒãã䜿çšããInterlocked.CompareExchangeã®ä»£ããã«ããã¯ïŒããïŒã䜿çšããŠã¹ã¬ããã»ãŒããæäŸããŸãã éçã€ãã³ãã®å Žåãããã¯ïŒtypeofïŒã¯ã©ã¹ïŒïŒã䜿çšãããŸãã CïŒ3ã®ã³ã³ãã€ã©ã®æé»çãªã€ãã³ãå®çŸ©ã«äŒŒãã³ãŒãã¯æ¬¡ã®ãšããã§ãã
class Class { EventHandler changed; public event EventHandler Changed { add { lock(this) { changed = changed + value; } } remove { lock(this) { changed = changed - value; } } } }
ããã«ãã¯ã©ã¹å ã®ã€ãã³ãã®åŠçã¯ãããªã²ãŒããšåæ§ã«å®è¡ãããŸãã + =ããã³-=è¿œå /åé€ã¡ãœããããã€ãã¹ããŠãDelegate.Combineããã³Delegate.RemoveãçŽæ¥åŒã³åºããŸãã ãã®å€æŽã«ãããCïŒ4ã§ãããžã§ã¯ãããã«ãã§ããªããªãå¯èœæ§ããããŸãïŒ CïŒ3ã§ã¯ã+ =ãš-=ã®çµæã¯ããªã²ãŒãã§ããããªããªãã å€æ°ãå²ãåœãŠãçµæã¯ãåžžã«å²ãåœãŠãããå€ã§ãã CïŒ4ã§ã¯ãçµæã¯ç¡å¹ã§ãã è¿œå /åé€ã¡ãœããã¯å€ãè¿ããŸããã
èšèªã®ç°ãªãããŒãžã§ã³ã§ã®äœæ¥ã®å€æŽã«å ããŠãããã«ããã€ãã®æ©èœããããŸãã
æ©èœïŒ1-ãµãã¹ã¯ã©ã€ããŒã©ã€ããšã¯ã¹ãã³ã·ã§ã³
ã€ãã³ãããµãã¹ã¯ã©ã€ããããšããã€ãã³ãããªã²ãŒãã®åŒã³åºããªã¹ãã«ãã€ãã³ããåŒã³åºããããšãã«åŒã³åºãããã¡ãœãããžã®åç §ãè¿œå ããŸãã ãããã£ãŠãã€ãã³ãã«ãµãã¹ã¯ã©ã€ãããŠãããªããžã§ã¯ããå æããŠããã¡ã¢ãªã¯ãã€ãã³ããããµãã¹ã¯ã©ã€ãã解é€ãããããã€ãã³ããå«ããªããžã§ã¯ããç Žæ£ããããŸã§è§£æŸãããŸããã ãã®æ©èœã¯ãã¢ããªã±ãŒã·ã§ã³ã®ã¡ã¢ãªãªãŒã¯ã®äžè¬çãªåå ã®1ã€ã§ãã
ãã®æ¬ ç¹ãä¿®æ£ããããã«ã匱ãã€ãã³ãããã°ãã°äœ¿çšãããŸãã匱ãã€ãã³ãã ãã®ãããã¯ã¯ãã§ã«Habréã§åãäžããããŠããŸã ã
æ©èœïŒ2-æ瀺çãªã€ã³ã¿ãŒãã§ã€ã¹ã®å®è£
ãã®ã€ã³ã¿ãŒãã§ã€ã¹ãæ瀺çã«å®è£ ãããŠããå Žåãã€ã³ã¿ãŒãã§ã€ã¹ã®äžéšã§ããã€ãã³ãã¯ãã£ãŒã«ããšããŠå®è£ ã§ããŸããã ãã®ãããªå Žåãæšæºã€ãã³ãå®è£ ãããããã£ãšããŠå®è£ ããããã«ã³ããŒããããã€ã³ã¿ãŒãã§ã€ã¹ã®ãã®éšåãæé»çã«å®è£ ããå¿ èŠããããŸãã ãŸãããã®ã€ãã³ãã®ã¹ã¬ããã»ãŒããäžèŠãªå Žåã¯ãæãåçŽã§å¹æçãªå®çŸ©ã䜿çšã§ããŸãã
EventHandler changed; event EventHandler ISomeInterface.Changed { add { changed += value; } remove { changed -= value; } }
æ©èœïŒ3-ã»ãŒãã³ãŒã«
åŒã³åºãåã®ã€ãã³ãã®nullããã§ãã¯ããå¿ èŠããããŸããããã¯ãäžèšã®ããªã²ãŒãã®äœæ¥ããåŸãããŸãã ã³ãŒãã¯ããããæé·ããå°ãªããšã2ã€ã®æ¹æ³ãããããšãåé¿ããŸãã æåã®æ¹æ³ã¯ããžã§ã³ã¹ããŒãã®èæžCïŒin depthã§èª¬æãããŠããŸãã
public event EventHandler Changed = delegate { };
çãç°¡æœã ã€ãã³ãããªã²ãŒãã空ã®ã¡ãœããã§åæåãããããnullã«ãªãããšã¯ãããŸããã ããªã²ãŒããããã®ã¡ãœãããæžç®ããããšã¯äžå¯èœã§ãããªããªã ããªã²ãŒãã®åæåäžã«å®çŸ©ãããããã°ã©ã å ã®ã©ãããã§ãååããªã³ã¯ããããŸããã
2çªç®ã®æ¹æ³ã¯ãå¿ èŠãªnullãã§ãã¯ãå«ãã¡ãœãããèšè¿°ããããšã§ãã ãã®ææ³ã¯ãæ¡åŒµã¡ãœãããå©çšå¯èœãª.NET 3.5以éã§ç¹ã«ããŸãæ©èœããŸãã æ¡åŒµã¡ãœãããåŒã³åºããšãããããåŒã³åºããããªããžã§ã¯ãã¯ãã®ã¡ãœããã®åãªããã©ã¡ãŒã¿ãŒã§ããããããã®ãªããžã§ã¯ãã¯ãã®å Žåã«äœ¿çšããã空ã®åç §ã«ããããšãã§ããŸãã
public static class EventHandlerExtensions { public static void SafeRaise(this EventHandler handler, object sender, EventArgs e) { if(handler != null) handler(sender, e); } public static void SafeRaise<TEventArgs>(this EventHandler<TEventArgs> handler, object sender, TEventArgs e) where TEventArgs : EventArgs { if(handler != null) handler(sender, e); } }
ãããã£ãŠãChanged.SafeRaiseïŒthisãEventArgs.EmptyïŒãªã©ã®ã€ãã³ããããªã¬ãŒã§ããã³ãŒãè¡ãç¯çŽã§ããŸãã EventArgs.Emptyãããå Žåãæ瀺çã«æž¡ããªãããã«ãæ¡åŒµã¡ãœããã®3çªç®ã®ããªã¢ã³ããå®çŸ©ããããšãã§ããŸãã ãã®åŸãã³ãŒãã¯Changed.SafeRaiseïŒããïŒã«åæžãããŸããããã®ã¢ãããŒãã¯ãå§ãããŸããã ããŒã ã®ä»ã®ã¡ã³ããŒã®å Žåã空ã®åŒæ°ãæž¡ãã»ã©æ瀺çã§ã¯ãªãå ŽåããããŸãã
埮åŠãªçªå·4-æšæºå®è£ ã®äœãåé¡ã«ãªã£ãŠããŸããïŒ
ReSharperããæã¡ã®å Žåã¯ã 圌ã®æ¬¡ã®ã¡ãã»ãŒãžãèŠãããšãã§ããŸã ã ãªãŸã«ãããŒã ã¯ããã¹ãŠã®ãŠãŒã¶ãŒãã€ãã³ã/ããªã²ãŒãã®äœæ¥ã«ã€ããŠãµãã¹ã¯ãªãã·ã§ã³è§£é€/æžç®ã®èŠ³ç¹ããååã«ç¥ããããŠããããã§ã¯ãªãããããã§ããã€ãã³ãã¯ãŠãŒã¶ãŒã«å¯ŸããŠã§ã¯ãªããã ã ãã®ãããªæ©èœããããããã¯ããªãã®ã³ãŒãã«æ®ã£ãŠããã¯ãã§ãã
ããŒãã¹ïŒã³ã³ãã©ã€ãã³ããäœæãããã€ã¯ããœããã®è©Šã¿
CïŒ4ã®æåã®ããŒã¿çã§ã¯ãMicrosoftã¯ã€ãã³ãã«ççŸãè¿œå ããããšããŸããã ããã«ãããEventHandler <EventArgs>ã·ã°ããã£ãæã€ã¡ãœããã䜿çšããŠEventHandler <MyEventArgs>ã€ãã³ãããµãã¹ã¯ã©ã€ãã§ããç°ãªãïŒãã ãé©åãªïŒã·ã°ããã£ãæã€ããã€ãã®ã¡ãœãããã€ãã³ãããªã²ãŒãã«è¿œå ããããŸã§ãã¹ãŠãæ©èœããŸããã ãã®ãããªã³ãŒãã¯ã³ã³ãã€ã«ãããŸããããå®è¡æãšã©ãŒã§ã¯ã©ãã·ã¥ããŸããã ã©ãããã圌ãã¯ãããåé¿ããããšãã§ãããCïŒ4ã®ãªãªãŒã¹ã§ã¯ãEventHandlerã®ççŸãç¡å¹ã«ãªããŸããã
ãµãã¹ã¯ã©ã€ãæã«ããªã²ãŒãã®æ瀺çãªäœæãçç¥ããå Žåãããã¯ããã»ã©é¡èã§ã¯ãããŸãããããšãã°ã次ã®ã³ãŒãã¯æ£åžžã«ã³ã³ãã€ã«ãããŸãã
public class Tests { public event EventHandler<MyEventArgs> Changed; public void Test() { Changed += ChangedMyEventArgs; Changed += ChangedEventArgs; } void ChangedMyEventArgs(object sender, MyEventArgs e) { } void ChangedEventArgs(object sender, EventArgs e) { } }
ããã¯ãã³ã³ãã€ã©èªäœãæ°ããEventHandler <MyEventArgs>ïŒ...ïŒãäž¡æ¹ã®ãµãã¹ã¯ãªãã·ã§ã³ã«çœ®ãæããããã§ãã å°ãªããšã1ã€ã®å Žæã§æ°ããEventHandler <EventArgs>ïŒ...ïŒã䜿çšãããšãã³ã³ãã€ã©ãŒã¯ãšã©ãŒãå ±åããŸã-EventHandler <System.EventArgs>ã®ã¿ã€ããEventHandler <Events.MyEventArgs>ã«å€æããããšã¯ã§ããŸããïŒããã§Eventsã¯ãã¹ãã®åå空éã§ãïŒãããžã§ã¯ãïŒã
ãœãŒã¹
以äžã¯ãœãŒã¹ã®ãªã¹ãã§ããããã®äžéšã¯èšäºã®äœæã«äœ¿çšãããŸããã Jon SkeetïŒJon SkeetïŒã®æ¬ãèªãããšããå§ãããŸãããã®æ¬ã§ã¯ãããªã²ãŒãã ãã§ãªããä»ã®å€ãã®èšèªããŒã«ã«ã€ããŠã詳ãã説æããŠããŸãã
- ãžã§ã³ã»ã¹ããŒãã CïŒã®è©³çŽ°ã第2ç
- ã¯ãªã¹ãããŠãºã CïŒ4ãããŒãIïŒããã¯ã§ã€ãã³ããå°ãèŠçŽãããŸã
- ã¯ãªã¹ãããŠãºã CïŒ4ãããŒãIIïŒæå³ã®å€æŽãš+ = /-=ã§ã€ãã³ããå°ãèŠçŽãããŸã
- ã¯ãªã¹ãããŠãºã CïŒ4ãããŒãIIIïŒé倧ãªå€æŽã§ã€ãã³ããå°ãèŠçŽãããŸã
- ã¯ãªã¹ãããŠãºã ã€ãã³ãã¯CïŒ4ã§å°ãèŠçŽãããŸãããã®åŸïŒå¹æçãªã€ãã³ã
- MSDN 10.7ã€ãã³ã -.NET 1.1ã®CïŒèšèªä»æ§ã®äžéš
- MSDN æ¹æ³ïŒã€ãã³ãããããã£ã䜿çšããŠè€æ°ã®ã€ãã³ããåŠçãã
- JetBrains ReSharperã ããªã²ãŒãæžç®ã«ã¯äºæž¬äžå¯èœãªã»ãã³ãã£ã¯ã¹ããããŸã
- StackOverflowã®è³ªåã .NET 4.0ããã³CïŒ4.0ã§ã®ã€ãã³ããšããªã²ãŒãã®ççŸ