public void SimpleDelagateLambda() { Console.WriteLine("\n\t DemoLambda.SimpleDelegateLambda()..."); // init delegate using delegate declaration: // public delegate string GetAString(); // declared in class above GetAString fL1 = () => "Lambda implements delegate GetAString"; Console.WriteLine($"use GetAString() via fL1 delegate: '{fL1()}' "); // init delegate using delegate declaration: // public delegate string GetAString(); // declared in class above GetAString fM2 = () => this.ToString(); Console.WriteLine($"use GetAString() via fM2 delegate: '{fM2()}' "); // init delegate using delegate declaration: // public delegate string GetAString(); // declared in class above GetAString fL2 = () => $"Lambda #{Id} implements delegate GetAString"; Console.WriteLine($"use GetAString() via fL2 delegate: '{fL2()}' "); // init delegate using delegate declaration: // public delegate int ScaleBy10(int n); // declared in class above ScaleBy10 fL3 = n => n * 10; Console.WriteLine($"use ScaleBy10(27) via fL3 delegate: '{fL3(27)}' "); // init delegate using delegate declaration: // public delegate int ScaleBy10(int n); // declared in class above ScaleBy10 fM4 = n => this.MultiplyByTen(n); Console.WriteLine($"use MultiplyByTen(27) via fM4 delegate: '{fM4(27)}' "); Console.WriteLine("\n\t DemoLambda.SimpleDelegateLambda()... done!"); }
public void SimpleDelagate() { Console.WriteLine("\n\t DemoLambda.SimpleDelagate()..."); // init delegate using delegate declaration: // public delegate string GetAString(); // declared in class above GetAString fM1 = new GetAString(ToString); // init delegate Console.WriteLine($"use GetAString() via fM1 delegate: '{fM1()}' "); GetAString fM2 = ToString; // init delegate without 'new' Console.WriteLine($"use GetAString() via fM2 delegate: '{fM2()}' "); // init delegate using delegate declaration: // public delegate int ScaleBy10(int n); // declared in class above ScaleBy10 fM3 = new ScaleBy10(MultiplyByTen); Console.WriteLine($"use MultiplyByTen(27) via fM3 delegate: '{fM3(27)}' "); ScaleBy10 fM4 = MultiplyByTen; // init delegate without 'new' Console.WriteLine($"use MultiplyByTen(27) via fM4 delegate: '{fM4(27)}' "); Console.WriteLine("\n\t DemoLambda.SimpleDelagate()... done!"); }