开发者

Func and List<string>

开发者 https://www.devze.com 2023-02-05 05:28 出处:网络
I have defined the following Dictionary<string, Func<string, List<string>>> test1 = new Dictionary<string, Func<string, List<string>>>();

I have defined the following

Dictionary<string, Func<string, List<string>>> test1 = new Dictionary<string, Func<string, List<string>>>();

also I have

    private string fred(List<string> Parms)
    {

        return "Tes开发者_如何学Pythont";
    }

how do I add fred to the dictionary? I have tried

       test1.Add("Test",fred);

but I get an error, if I replace the List for a string everything is ok.


You have the arguments around the wrong way. A Func<X,Y> takes an X and returns a Y. Your dictionary should be:

Dictionary<string, Func<List<string>,string>>


Dictionary<string, Func<string, List<string>>> test1 = new Dictionary<string, Func<string, List<string>>>();

should be

Dictionary<string, Func<List<string>, string>>> test1 = new Dictionary<string, Func<List<string>, string>>();
0

精彩评论

暂无评论...
验证码 换一张
取 消