.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

multicast delegates and example

Posted By:Jegan R       Posted Date: November 01, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Delegate that can have more than one element in its invocation List
 

using System;
namespace SampleMultiCastDelegate
{
  class MultiCast
  {
    public delegate string strMultiCast(string s);
  }
}


MainClass defines the static methods having same signature as delegate.
using System;

namespace SampleMultiCastDelegate
{
 
  public class MainClass
  {
    public MainClass()
    { 
    }

    public static string Jump(string s)
    {
      Console.WriteLine("Jump");
      return String.Empty;
    }

    public static string Run(string s)
    {
      Console.WriteLine("Run");
      return String.Empty;
    }

    public static string Walk(string s)
    {
      Console.WriteLine("Walk");
      return String.Empty;      
    }
  }
}


The Main class:

using System;
using System.Threading;
namespace SampleMultiCastDelegate
{
 
  public class MainMultiCastDelegate
  {
    public static void Main()
    {
      MultiCast.strMultiCast  Run,Walk,Jump;

      MultiCast.strMultiCast    myDelegate;

       ///here mydelegate used the Combine method of System.MulticastDelegate
      ///and the delegates combine 
      myDelegate=(MultiCast.strMultiCast)System.Delegate.Combine(Run,Walk); 
               
    }
  }
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend