With C# 7 we get the feature to define local functions:
private void Foo()
{
string myString = getMyString();
string getMyString()
{
return "Hello SO!";
}
}
Is there a benefit or drawback to using this over Func<> or Action<>?
private void Foo()
{
Func<string> getMyString = () =>
{
return "Hello SO!";
};
string myString = getMyString();
}
I'm only talking about using the function inside of Foo. Of course when I want to pass the function around I need to use Func<> or Action<>, but when I only want to use it in this scope is one of those ways superior over the other, and if so, how?