CSharp - Get the return value from multicast delegate

Description

Get the return value from multicast delegate

Demo

using System;

public delegate int MultiDel(int a, int b);

class Program/*w  w  w . j a  v  a 2  s  .  c  om*/
{
    public static int Sum(int a, int b)
    {
        Console.Write("Program.Sum->\t");
        Console.WriteLine("Sum={0}", a + b);
        return a + b;
    }
    public static int Difference(int a, int b)
    {
        Console.Write("Program.Difference->\t");
        Console.WriteLine("Difference={0}", a - b);
        return a - b;
    }
    public static int Multiply(int a, int b)
    {
        Console.Write("Program.Multiply->\t");
        Console.WriteLine("Multiplication={0}", a * b);
        return a * b;
    }

    static void Main(string[] args)
    {
        MultiDel md = new MultiDel(Sum);
        md += Difference;
        md += Multiply;
        int c = md(10, 5);
        Console.WriteLine("Analyzing the value of c");
        Console.WriteLine("c={0}", c);
    }
}

Result

Related Topic