¿Cómo usas Func <> y Action <> al diseñar aplicaciones?
Todos los ejemplos que puedo encontrar sobre Func <> y Action <> sonsencillo como en el de abajo donde vescómo técnicamente funcionan, pero me gustaría verlos en ejemplos en los que resuelven problemas que anteriormente no podían resolverse o podrían resolverse solo de una manera más compleja, es decir, sé cómo funcionan y puedo ver que lo son.tenso y poderoso, así que quiero entenderlos en unasentido más amplio de qué tipo de problemas resuelven y cómo podría usarlos en el diseño de aplicaciones.
¿De qué manera (patrones) utiliza Func <> y Action <> para resolver problemas reales?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestFunc8282
{
class Program
{
static void Main(string[] args)
{
//func with delegate
Func<string, string> convert = delegate(string s)
{
return s.ToUpper();
};
//func with lambda
Func<string, string> convert2 = s => s.Substring(3, 10);
//action
Action<int,string> recordIt = (i,title) =>
{
Console.WriteLine("--- {0}:",title);
Console.WriteLine("Adding five to {0}:", i);
Console.WriteLine(i + 5);
};
Console.WriteLine(convert("This is the first test."));
Console.WriteLine(convert2("This is the second test."));
recordIt(5, "First one");
recordIt(3, "Second one");
Console.ReadLine();
}
}
}