メソッドからアクションを返す方法を見つけようとしています。このオンラインの例は見つかりません。実行しようとしているコードは次のとおりですが、失敗します。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
var testAction = test("it works");
testAction.Invoke(); //error here
Console.ReadLine();
}
static Action<string> test(string txt)
{
return (x) => Console.WriteLine(txt);
}
}
}