doc_mmDelegate1.htm ( Webpage : delegate example) , please also visit doc2
http://msdn.microsoft.com/en-us/library/ms173173(VS.80).aspx

Use a delegate when:

  • An eventing design pattern is used.
  • It is desirable to encapsulate a static method.
  • The caller has no need access other properties, methods, or interfaces on the object implementing the method.
  • Easy composition is desired.
  • A class may need more than one implementation of the method.

Use an interface when:

  • There are a group of related methods that may be called.
  • A class only needs one implementation of the method.
  • The class using the interface will want to cast that interface to other interface or class types.
  • The method being implemented is linked to the type or identity of the class: for example, comparison methods.

Step 1:

Step: 2 Code

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class _Default : System.Web.UI.Page
{
public delegate void Del(string message);
protected void Page_Load(object sender, EventArgs e)
{
// Instantiate the delegate.
Del handler = DelegateMethod;
L1.Text+="<br/> Page_Laod() started";
String str = " <br/> string used : <font color='red'>public delegate void Del(string message)</font>";
// Call the delegate.
handler(str);

}
// Create a method for a delegate.
public void DelegateMethod(string message)
{
L1.Text += "<br/>DelegateMethod(string message) started ";
L1.Text += message;
}

}
 

Step 3: runtime analysis