Created
September 12, 2017 19:18
-
-
Save airbreather/fb012c59f31143eaf30ed260e275ece5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A | |
| { | |
| public event EventHandler Foo; | |
| public void RaiseFoo() => this.Foo?.Invoke(this, EventArgs.Empty); | |
| } | |
| class B | |
| { | |
| public int Val; | |
| public void Subscribe(A a) => a.Foo += this.Handler; | |
| public void Handler(object sender, EventArgs args) | |
| { | |
| ((A)sender).Foo -= this.Handler; | |
| Console.WriteLine("B{0} Handled", this.Val); | |
| } | |
| } | |
| A a = new A(); | |
| B b1 = new B { Val = 1 }; | |
| B b2 = new B { Val = 2 }; | |
| B b3 = new B { Val = 3 }; | |
| b1.Subscribe(a); | |
| a.Foo -= b3.Handler; | |
| b2.Subscribe(a); | |
| a.RaiseFoo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment