Kja*_*ara 2 c# delegates partial-application
考虑以下方法:
int Foo(string st, float x, int j)
{
...
}
Run Code Online (Sandbox Code Playgroud)
Func<float, int>现在我想通过提供参数st和 的值将其包装在类型的委托中j。但我不知道语法。有人可以帮忙吗?
这是这个想法(可能看起来有点像 Haskell):
Func<float, int> myDelegate = new Func<float, int>(Foo("myString", _ , 42));
// by providing values for st and j, only x is left as a parameter and return value is int
Run Code Online (Sandbox Code Playgroud)
这应该可以解决问题:
Func<float, int> f = (x) => { return Foo("myString", x, 42); };
Run Code Online (Sandbox Code Playgroud)
按照您想要的方式部分应用函数目前只能在 F# 中实现,而不能在 C# 中实现。
| 归档时间: |
|
| 查看次数: |
3971 次 |
| 最近记录: |