Func and 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>>();
精彩评论