Monday, August 3, 2009

simply Delegates

namespace mynamespace
{
public partial class Testclass
{
//delegate declaration
public delegate void mydelegate(string email, string eName);

//method to use with the delagate
public void methodfordelegate(string email, string eName)
{
try
{
loadContactPage(email, eName);
}
catch (Exception ex)
{
Messagebox.Show(ex.ToString());
}
}

//delegate object declaration
static mydelegate OBJmydelegate;

//----------------------------------------------------------------------
public void initializedelegate()
{
OBJmydelegate = new mydelegate(methodfordelegate);
}

public static void UseOfDelegate(string email, string eName)
{
try
{
OBJmydelegate.Invoke(email, eName);
}
catch (Exception ex)
{
Messagebox.Show(ex.ToString());
}
}

}
}

No comments:

Post a Comment