public class Test1
{
// Create Delegate
public delegate int AddDel(int a, int b);
public int Add(int a, int b)
{
return a + b;
}
public void TestM()
{
// Create instance of Delegate and pass method as a parameter
AddDel addDel = new AddDel(Add);
addDel.Invoke(10, 20);
}
}
Note: Method parameter and return type must be same as delegate
{
// Create Delegate
public delegate int AddDel(int a, int b);
public int Add(int a, int b)
{
return a + b;
}
public void TestM()
{
// Create instance of Delegate and pass method as a parameter
AddDel addDel = new AddDel(Add);
addDel.Invoke(10, 20);
}
}
Note: Method parameter and return type must be same as delegate
No comments:
Post a Comment