func-vs-action-vs-predicate

  • Thread starter Thread starter Markus Freitag
  • Start date Start date
M

Markus Freitag

Guest
Hello,

I found this

For me is not clear.
When do I take this?
Where are the advantages?
Can someone explain it or does someone know a good link?

That makes sense, if I create a framework, offer it third, because then could perform other calculations.
Is that right?
That does not make much sense for my consumer use?

public delegate string Foo (DateTime time);
is the same as
public func<DateTime,string> Foo (DateTime time);

public void GoesToFunc7(int x, int y)
{
Console.WriteLine($"{x*y}-TESTFunc7");
}

public bool GoesToFunc8(int x, int y)
{
Console.WriteLine($"{x * y}-TESTFunc8");
return true;
}

public override void Step1()
{
CommonData.ErrorManager.MREvNotBusyTrack01.Reset();


Func<int, int> func4 = (int x) => { return x + 1; };
Console.WriteLine(func4.Invoke(1));

Func<int, int, int> func5 = (x, y) => x * y;
Console.WriteLine(func5.Invoke(2, 2));

Func<int, int, string> func6 = (x, y) => (x * y).ToString();
Console.WriteLine(func6.Invoke(2, 2));


Predicate<int> predicate8 = (x) => GoesToFunc8(x, x); // return bool


//Action<int, int> func7 = (x, y) => (x * y).ToString();
Action<int, int> func7 = (x, y) => GoesToFunc7(x, y);
//Console.WriteLine(func7.Invoke(2, 2));

func7.Invoke(5, 7);
predicate8.Invoke(9);

}


Best regards, Markus

Continue reading...
 
Back
Top