Delegates in ASP.NET with easy example

Delegates in .NET

using System;

main();

private  void main()
{
// Action is Like Void/Sub..no return
Action<string> log = Console.WriteLine;
log("Hey There");
// 2 Ways to Call a Func Delegate
ProcessData(Weightcheck); // By passing a REAL Function
ProcessData( (a,b) => { Console.WriteLine(b);return true; } ); // By using a Anonymous Function (Lambada Expression)
// When passing Func/Action via function parameter, Remember that DATA will always be supplied from the Calling Function Body.
}



private void ProcessData(Func<int,string, bool> GetWeight)
{


bool w = GetWeight(22,"Khan");
if (w) Console.WriteLine(1);
else
Console.WriteLine(2);

}

private bool Weightcheck(int weight, string name)
{
return false;
}
Posted by:

No comments posted.

Name :  

Email :  

Comment Below