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();