Simple Demonstration of Func<> Delegate

Hmanjarawala
Posted by Hmanjarawala under C# category on | Points: 40 | Views : 1291
class MyClass
{
public bool GreaterThen(int a, int b)
{
return (a > b);
}

public bool LessThen(int a, int b)
{
return (a < b);
}

public bool EqualTo(int a, int b)
{
return (a == b);
}

public string Message(string m)
{
return m;
}

public void ExecuteMethod(Func<int, int, bool> callBack, int param1, int param2)
{
bool isSuccess = false;
isSuccess = callBack(param1, param2);
MessageBox.Show(isSuccess.ToString());
}

public void ExecuteMethod(Func<string, string> callBack, string message)
{
MessageBox.Show(message);
}
}


static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
MyClass c = new MyClass();
c.ExecuteMethod(c.GreaterThen, 5, 10);
c.ExecuteMethod(c.LessThen, 5, 10);
c.ExecuteMethod(c.EqualTo, 5, 10);
c.ExecuteMethod(c.Message, "Hi, Himanshu");
}

}

Comments or Responses

Login to post response