Results 1 to 6 of 6

Thread: Multicast delegates of C sharp

  1. #1
    Join Date
    Dec 2009
    Posts
    59

    Multicast delegates of C sharp

    Hello Guys,

    I just started the C sharp programming course. Currently I have little bit knowledge about the delegates of C sharp. But don't know anything about the Multicast delegates of C sharp. If don't if Multicast delegates is any special type of C sharp delegates. I have refferred lots of C sharp book for get information over this concept , but didn't get enough details. Please let me aware about the Multicast delegates of C sharp. I would appreciate your any help.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Multicast delegates of C sharp

    The Multicast delegates is mostly used along with events in the C sharp. Multicast delegates is basically used for the generic class libraries. This class libraries has generic functionality defined. To use Multicast delegates you first need to define delegates that you wan to use. After this you need to make single or more instances for that delegate. The generic class may need to call certain functions defined by the end user implementing the generic class.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Multicast delegates of C sharp

    The following C sharp example depicts will you the method to compose multicast delegates. A useful property of multicast delegate objects is that they can be assigned to single delegate instance using the + operator.
    Example:
    Code:
    delegate void Del1(string s1);
    
    class TestClass1
    {
        static void Hello(string s1)
        {
            System.Console.WriteLine("  Hello, {0}!", s);
        }
    
        static void Goodbye(string s1)
        {
            System.Console.WriteLine("  Goodbye, {0}!", s);
        }
    
        static void Main()
        {
            Del a1, b1, c1, d1;
    
            
            a1 = Hello;
    
            // Create the delegate object b that references 
           
            b1 = Goodbye;
    
            // The two delegates, a and b, are composed to form c1: 
            c1 = a1 + b1;
    
            // Remove a from the composed delegate, leaving d1, 
          
            d1 = c1 - a1;
    
            System.Console.WriteLine("Invoking delegate a1:");
            a("A1");
            System.Console.WriteLine("Invoking delegate b1:");
            b("B1");
            System.Console.WriteLine("Invoking delegate c1:");
            c("C1");
            System.Console.WriteLine("Invoking delegate d1:");
            d("D1");
        }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Multicast delegates of C sharp

    Hi,

    Multicast delegates of C # comprise single or more references to the methods. The return type of this delegates of C sharp is must be 'void'. In most of the case this C sharp delegates are used for improving the application performance. Multicast delegates are basically used for to encapsulating the call from caller of class methods. It also essential for to call a method asynchronously.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Multicast delegates of C sharp

    Hi friend,

    I have one C sharp example which will explains you the Multicast delegates declaration of C sharp. Please study this example care fully:
    Code:
    using System;
    
    class MainClass3
    {
      delegate int MyDelegate3(string s3);
      static void Main(string[] args)
      {
        string MyString3 = "Hello World";
    
        
        MyDelegate Multicast3 = null;
    
        Multicast3 += new MyDelegate(DoSomething3);
        Multicas3t += new MyDelegate(DoSomething4);
    
        Multicast3(MyString);
      }
    
      static int DoSomething3(string s3)
      {
        Console.WriteLine("DoSomething");
        
        return 0;
      }
      static int DoSomething4(string s)
      {
          Console.WriteLine("DoSomething");
        return 0;
      }
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Multicast delegates of C sharp

    Hi,

    Multicast delegates are those delegated which have referenced to one or more than methods of class. It also valid in C sharp to use multicast delegates with parameters or without parameter list. ulticast delegates must contain only methods that return void, else there is a run-time exception. The operator known as ' - 'can be used to remove a component delegate from a composed delegate. I hope you will understand multicast delegates with this information.

Similar Threads

  1. Sharp 007SH Hybrid An 3D Clamshell Android Phone by Sharp
    By jackalz in forum Web News & Trends
    Replies: 3
    Last Post: 22-05-2011, 07:28 AM
  2. Hyper-V Multicast problems
    By Author in forum Windows Software
    Replies: 5
    Last Post: 06-04-2010, 04:06 AM
  3. Use of delegates in C sharp
    By opaper in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 01:44 PM
  4. What do you mean by Csharp Delegates?
    By Jarini in forum Software Development
    Replies: 3
    Last Post: 11-11-2009, 09:57 PM
  5. Replies: 1
    Last Post: 24-07-2007, 10:22 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,280,910.54308 seconds with 17 queries