C# 调用Func<;字符串,对象>;在兰姆达

C# 调用Func<;字符串,对象>;在兰姆达,c#,C#,我很困惑,为什么我不能把它称为一个函数,我如何让自己把它称为一个函数 Error 1 'fn' is a 'variable' but is used like a 'method' 来源 Func<List<object>, List<object>, Func<string, object>> test; test = (ls, fn) => fn(null); Func检验; 测试=(ls,fn)=>fn(空); 您可能需要

我很困惑,为什么我不能把它称为一个函数,我如何让自己把它称为一个函数

Error   1   'fn' is a 'variable' but is used like a 'method'
来源

Func<List<object>, List<object>, Func<string, object>> test;
test = (ls, fn) => fn(null);
Func检验;
测试=(ls,fn)=>fn(空);

您可能需要以下内容

Func<List<object>, Func<string, List<object>>, List<object>> test;
我很困惑

是的。让我们相信你

这个怎么了

现在
ls
的类型是
List
fn
的类型是
Func
。因此,当调用
fn
时,它将返回
测试所需的
列表

有道理吗


请记住,在
Func
中,A和B是参数类型,R是返回类型。

您可能需要以下内容:

    static void Main(string[] args)
    {
        Func<List<object>, List<object>, Func<string, object>> test = Test;

    }

    private static Func<string, object> Test(List<object> objects, List<object> list)
    {
        throw new NotImplementedException();
    }
static void Main(字符串[]args)
{
Func试验=试验;
}
专用静态函数测试(列表对象、列表)
{
抛出新的NotImplementedException();
}

我不知道你想要什么,但这可以编译并运行:

public void SomeMethod()
{
    Func<List<object>, List<object>, Func<string, object>> test = (a, b) => 
    {
        a = b;
        return AnotherMethod;
    };
}

public object AnotherMethod(string value)
{
    return (object)value;
}
public void SomeMethod()
{
Func测试=(a,b)=>
{
a=b;
回归分析法;
};
}
公共对象AnotherMethod(字符串值)
{
返回(对象)值;
}

fn的定义是什么?fn有类型列表
fn
是一个
列表。您的
test
返回一个
Func
这个函数应该做什么?它应该接收一个
List,Func
并返回
List
返回值是最后一个参数吗?这是违反直觉的,因为C#在参数之前总是有返回类型这仍然不会编译为
fn
返回
对象
,并且代理假设返回类型是
List
@BruteCode有趣的是,Eric有一篇关于这个主题的博客文章,如果记忆有用的话。哦,对了,我循环我没有在这里添加的元素,但是这很好enough@Servy:这是关于你的博客。
Func<List<object>, List<object>, Func<string, object>> test;
test = (ls, fn) => fn(null);
Func<List<object>, Func<string, List<object>>, List<object>> test;
test = (ls, fn) => fn(null);
    static void Main(string[] args)
    {
        Func<List<object>, List<object>, Func<string, object>> test = Test;

    }

    private static Func<string, object> Test(List<object> objects, List<object> list)
    {
        throw new NotImplementedException();
    }
public void SomeMethod()
{
    Func<List<object>, List<object>, Func<string, object>> test = (a, b) => 
    {
        a = b;
        return AnotherMethod;
    };
}

public object AnotherMethod(string value)
{
    return (object)value;
}