gpt4 book ai didi

c# - 从 C# 方法返回方法

转载 作者:行者123 更新时间:2023-11-30 19:18:02 25 4
gpt4 key购买 nike

我找到了 this post这解释了如何在 C# 中将方法作为参数传递。

我需要知道的是如何返回一个方法作为另一个方法调用的结果。

method = DoSomething()
result = method()

最佳答案

您需要使用 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;
}

关于c# - 从 C# 方法返回方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14416936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com