最初の行はstopMachineryDelegate、パラメーターを受け入れず、値を返さないデリゲート ( ) として、デリゲート タイプ ( )を定義するために使用されますvoid。
2行目は、という名前のそのタイプのフィールドを宣言していますStopMachinery。その時点で、StopMachinerynull です。
3 行目の背後には、構文糖衣があります。StopMachineryその時点で が null の場合、その の新しいインスタンスを作成し、メソッド デリゲートをその呼び出しリストにMulticastDelegate追加します。painting
そのフィールドに単一のデリゲートのみを割り当てたい場合は、次のように簡単に記述できます。
// implicitly wrap the `painting` method into a new delegate and
// assign to the `StopMachinery` field
this.StopMachinery = painting;
一方、 using を使用+=すると、呼び出し時に呼び出されるデリゲートのリストを指定できますStopMachinery。
this.StopMachinery += painting;
this.StopMachinery += someOtherMethod;
this.StopMachinery += yetAnotherMethod;
後者の場合、StopMachineryデリゲートの呼び出しは、指定された順序で、呼び出しリスト内の各メソッドを同期的に呼び出します。