Last active
November 4, 2015 14:57
-
-
Save manuelleduc/d846a2a84aa7004c42a5 to your computer and use it in GitHub Desktop.
Demo delegate + lambda c#
This file contains 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ProtoLambdaCSharp | |
{ | |
public delegate void KCallback(object p); | |
public delegate void Runner(); | |
public class KExtCallback { | |
public readonly Runner _run1; | |
public readonly Runner _run2; | |
public KExtCallback(Runner run1, Runner run2) | |
{ | |
this._run1 = run1; | |
this._run2 = run2; | |
} | |
} | |
} |
This file contains 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ProtoLambdaCSharp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var s = new Service(); | |
KCallback cb = (p) => Console.WriteLine(p.ToString()); | |
s.executeCallback(cb); | |
int i = 0; | |
Runner run1 = () => | |
{ | |
i = i + 1; | |
Console.WriteLine("Hello " + i); | |
}; | |
Runner run2 = () => | |
{ | |
i = i + 2; | |
Console.WriteLine("world " + i); | |
}; | |
KExtCallback ecb = new KExtCallback(run1, run2); | |
s.executeKExtCallback(ecb); | |
} | |
} | |
} |
This file contains 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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ProtoLambdaCSharp | |
{ | |
class Service | |
{ | |
internal void executeCallback(KCallback cb) | |
{ | |
cb("Called"); | |
} | |
internal void executeKExtCallback(KExtCallback ecb) | |
{ | |
ecb._run1(); | |
ecb._run2(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment