Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C#でメソッドをパラメーターとして渡す方法を説明するこの投稿を見つけました。
私が知る必要があるのは、別のメソッド呼び出しの結果としてメソッドを返す方法です。
method = DoSomething() result = method()
Action<T>またはのいずれかを使用する必要がありますFunc<T>
Action<T>
Func<T>
このような:
private Action<string> Returns(string user) { return () => { Console.WriteLine("Hey {0}", user); }; }
またはこれ:
private Func<bool> TestsIsThirty(int value) { return () => value == 30; }
ほとんどの場合、戻り値の型をDelegate.
Delegate
ActionおよびFuncデリゲートを確認してください。
var method =()=> DoSomething(); result = method();