Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以将委托定义为c#中函数的限制吗?_C#_Delegates - Fatal编程技术网

我可以将委托定义为c#中函数的限制吗?

我可以将委托定义为c#中函数的限制吗?,c#,delegates,C#,Delegates,假设我有两个函数:f(x,y)和g(x)。在数学中,如果你有一个固定的y,比如y_fix,你可以定义: g(x) := f(x,y_fix) 现在假设g()是一个c#委托,f是一个实现的函数。 我能用类似的方法定义g(x)吗?e、 g public delegate double SingleVariableFunction(double x); public class SomeClass { SingleVariableFunction g; double y_fix;

假设我有两个函数:f(x,y)和g(x)。在数学中,如果你有一个固定的y,比如y_fix,你可以定义:

g(x) := f(x,y_fix)
现在假设g()是一个c#委托,f是一个实现的函数。 我能用类似的方法定义g(x)吗?e、 g

public delegate double SingleVariableFunction(double x);
public class SomeClass
{
    SingleVariableFunction g;
    double y_fix;

    public SomeClass()
    {
        y_fix = 2;
        g = f(  ,y_fix);    /// Is this possible somehow?
    }

    public double f(double x, double y)
    {
        return x + y;   
    }
}
它叫

在C#中,您可以使用lambda表达式构造
g

g = x => f(x, y_fix);

什么是
g=f(,y_fix)应该代表什么?
是打字错误吗?@Blorgbeard这是
f()
的第一个神秘参数。这是OP的问题。真棒@just.ru!C#做得太好了!