Users Online

· Guests Online: 112

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Implement Multicast Delegates

C# Program to Implement Multicast Delegates

 

This is a C# Program to implement multicast delegates.

Problem Description

This C# Program Implements Multicast Delegates.

Problem Solution

Here Multicast delegate is a delegate which holds a reference to more than one method.

Program/Source Code

Here is source code of the C# Program to Implement Multicast Delegates. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Implement Multicast Delegates
 */
using System;
delegate void dele(int a, int b);
public class Oper
{
    public static void Add(int a, int b)
    {
        Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
    }
 
   public static void Sub(int a, int b)
    {
        Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
    }
}
public class program
{
    static void Main()
    {
        dele del = new dele(Oper.Add);
        del += new dele(Oper.Sub);
        del(4, 2);
        del -= new dele(Oper.Sub);
        del(1, 9);
        Console.Read();
    }
}
Program Explanation

This C# program is used to implement multicast delegates. Using Add and Sub two methods perform addition and subtraction. The Multicast delegate is a delegate which holds a reference to more than one method. Using the delegate object variable ‘del’ we are calling the methods by passing the value as argument.

 
Runtime Test Cases
 
4 + 2 = 6
4 - 2 = 2
1 + 9 = 10

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.75 seconds
10,860,387 unique visits