Delegates and Lambdas
Func and Action
Func returns a value, while Action performs work without returning one.
Func and Action
FuncAction.cs
using System;
class Program
{
static void Main()
{
string word = ;
Func<string, string> bracket = text => "[" + text + "]";
string output = "";
Action<string> save = text => output = text;
save(bracket(word));
Console.WriteLine($"word={word}");
Console.WriteLine($"output={output}");
}
}
using System;
class Program
{
static void Main()
{
string word = ;
Func<string, string> bracket = text => "[" + text + "]";
string output = "";
Action<string> save = text => output = text;
save(bracket(word));
Console.WriteLine($"word={word}");
Console.WriteLine($"output={output}");
}
}
using System;
class Program
{
static void Main()
{
string word = ;
Func<string, string> bracket = text => "[" + text + "]";
string output = "";
Action<string> save = text => output = text;
save(bracket(word));
Console.WriteLine($"word={word}");
Console.WriteLine($"output={output}");
}
}
Func and Action
`Func` delegates return values, and `Action` delegates return `void`.