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//from  w w  w .java2s.c o  m
{
    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