topical media & game development

talk show tell print

mashup-amazon-13-13-01-Delegates-anonymousDelegate.aspx.cs / cs



  using System;
  using System.Data;
  using System.Configuration;
  using System.Web;
  using System.Web.Security;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;
  using System.Web.UI.HtmlControls;
  
  public partial class _Default : System.Web.UI.Page 
  {
      // Define a delegate type
      delegate string myDelegateType(string strMsg);
  
      protected void cmdGo_Click(object sender, EventArgs e)
      {          
          string strMyMessage = "Say Howdy!";
  
          // Declare an anonymous delegate
          myDelegateType myDelegate = delegate(string strMsg) {            
              string strFuncName = System.Reflection.MethodBase.GetCurrentMethod().Name;
              return "My function name is this: " + strFuncName + " and you told me to do this: " + strMsg;
          };
  
         // Fire the delegate
         lblResults.Text = myDelegate.Invoke(strMyMessage);     
      }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.