Skip to content

Instantly share code, notes, and snippets.

@uchidev
Created October 9, 2018 16:13
Show Gist options
  • Select an option

  • Save uchidev/7472da15f953ef05c13657d83715282a to your computer and use it in GitHub Desktop.

Select an option

Save uchidev/7472da15f953ef05c13657d83715282a to your computer and use it in GitHub Desktop.
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