Generic Delegate Action Func and Predicate
Generic Delegate Action Func and Predicate
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memory_understanding
{
//Generic Delegate with Action, Func and Predicate
class genericdelegate
{
static string getmessage(string hello)
{
return hello+"This is func delegate";
}
static void getmessageAction(string hello)
{
Console.WriteLine("This is Action delegate"+hello);
}
static bool getmessagePredicate(string hello)
{
if (hello == "Hello Predicate")
return true;
else
return false;
}
public static void Main()
{
//Func delegate will return a value and the last argument in the argument list is the return type
Func<string, string> fun = new Func<string, string>(getmessage);
string t = fun("Hello Func");
Console.WriteLine(t);
///Action Delegate will not return any value //
///
Action<string> act = new Action<string>(getmessageAction);
act("Hello Action");
//predicate Delegate return the boolean type//
Predicate<string> pre = new Predicate<string>(getmessagePredicate);
bool istrue=pre("Hello Predicate");
Console.WriteLine(istrue);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Memory_understanding
{
//Generic Delegate with Action, Func and Predicate
class genericdelegate
{
static string getmessage(string hello)
{
return hello+"This is func delegate";
}
static void getmessageAction(string hello)
{
Console.WriteLine("This is Action delegate"+hello);
}
static bool getmessagePredicate(string hello)
{
if (hello == "Hello Predicate")
return true;
else
return false;
}
public static void Main()
{
//Func delegate will return a value and the last argument in the argument list is the return type
Func<string, string> fun = new Func<string, string>(getmessage);
string t = fun("Hello Func");
Console.WriteLine(t);
///Action Delegate will not return any value //
///
Action<string> act = new Action<string>(getmessageAction);
act("Hello Action");
//predicate Delegate return the boolean type//
Predicate<string> pre = new Predicate<string>(getmessagePredicate);
bool istrue=pre("Hello Predicate");
Console.WriteLine(istrue);
Console.ReadLine();
}
}
}
Comments
Post a Comment