Unterricht Tag 5
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
namespace Tag_5_Unterricht;
|
||||
|
||||
public class Delegate
|
||||
{
|
||||
|
||||
delegate int MathOperation(int a, int b);
|
||||
delegate void SendEvent(string message);
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("Delegate:");
|
||||
Func<int, int, int> add = (a,b) => a + b;
|
||||
|
||||
MathOperation add2 = (a, b) => a + b;
|
||||
|
||||
Console.WriteLine(add2(1, 4));
|
||||
|
||||
SendEvent sendEvent;
|
||||
sendEvent = m => Console.WriteLine("Msg: " + m);
|
||||
sendEvent = (m => Console.WriteLine("New Message!")) + sendEvent;
|
||||
|
||||
sendEvent("Hello World");
|
||||
sendEvent("Hallo Welt");
|
||||
|
||||
var mOp = new MathOperation(add);
|
||||
mOp = new MathOperation((a, b) => a * b);
|
||||
|
||||
Console.WriteLine(mOp(2, 5));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user