private static void LambdaExample1() { Sum3Numbers sumFunc = (x, y, z) => x + y + z; int result = sumFunc.Invoke(10, 20, 30); Console.WriteLine(result); }
public void Run() { Sum3Numbers delegateSum = null; delegateSum += CalculateSum3Numbers; delegateSum += CalculateDif3Numbers; var result = delegateSum(9, 8, 7); // Will print: 6 Console.WriteLine(result); }
private static void DefineAndInitializeDelegates() { // Ex1: init delegate with a static function // Sum3Numbers sumFunc = Sum; // Ex2: init delegate with an instance function // MathHelper helper = new MathHelper(); // Sum3Numbers sumFunc = helper.Sum; // Ex3: init delegate with an anonimous function Sum3Numbers sumFunc = delegate(int x, int y, int z) { return(x + y + z); }; int result = sumFunc.Invoke(10, 20, 30); Console.WriteLine(result); }