Created
October 9, 2018 16:13
-
-
Save uchidev/7472da15f953ef05c13657d83715282a 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
| using System; | |
| namespace ConsoleApp2 | |
| { | |
| public class DelegateSample | |
| { | |
| public event Action<int>Fn; | |
| public void Run() | |
| { | |
| var a = new VmSample(this); | |
| a.Start(); | |
| Fn?.Invoke(10); | |
| a.Stop(); | |
| } | |
| } | |
| class VmSample | |
| { | |
| private readonly DelegateSample _sample; | |
| public VmSample(DelegateSample sample) | |
| { | |
| _sample = sample; | |
| } | |
| public void Start() | |
| { | |
| _sample.Fn += Method1; | |
| } | |
| public void Stop() | |
| { | |
| _sample.Fn -= Method1; | |
| } | |
| private void Method1(int a) | |
| { | |
| Method2(a * 2); | |
| } | |
| private void Method2(int x) | |
| { | |
| Console.WriteLine($"Method2 x={x}"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment