在字典中存储func时,参数类型不可分配

Gur*_*epS 0 c#

我有一个func,它接受一个T类参数并返回一个值.

我想将它存储在字典中,如下所示:

Dictionary<CustomerMilestones, Func<string, string>> coll = new Dictionary<CustomerMilestones, Func<string, string>>();

string Indicator = coll[CustomerMilestones.Ordered100Products].Invoke(customerId.ToString());

coll.Add(CustomerMilestones.Ordered100Products, Execute(Indicator);
Run Code Online (Sandbox Code Playgroud)

Execute是一个接受字符串但也返回字符串的方法.在最后一行,错误如下:

参数类型字符串不能分配给参数类型Func.

我究竟做错了什么?

Jon*_*eet 5

你不应该调用 Execute - 你只需要将它作为方法组提供:

coll.Add(CustomerMilestones.Ordered100Products, Execute);
Run Code Online (Sandbox Code Playgroud)