Skip to content

Instantly share code, notes, and snippets.

@BojanKomazec
Created December 21, 2015 14:20
Show Gist options
  • Save BojanKomazec/a1c200db3676675e5d28 to your computer and use it in GitHub Desktop.
Save BojanKomazec/a1c200db3676675e5d28 to your computer and use it in GitHub Desktop.
using System;
public class Program
{
public static void Main()
{
var c = new C();
c.FooCall(123);
c.FooCall(456);
}
}
public class C
{
private delegate void BarFixedInt(string s);
public void FooCall(int i)
{
this.Foo((s) => this.Bar(i, s));
}
private void Foo(BarFixedInt barFixedInt)
{
var s = "test1";
barFixedInt.Invoke(s);
// do something...
s = "test2";
barFixedInt.Invoke(s);
// do something
s = "test3";
barFixedInt.Invoke(s);
// etc...
}
private void Bar(int i, string s)
{
Console.WriteLine($"i = {i}, s = {s}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment