-1
如何使带有lambda函数的字典具有Func <>包含不同数量的参数?如何使带有lambda函数的字典具有不同数量的参数
Dictionary<string, Func<T, double>> operationsList
= new Dictionary<string, Func<T, double>>();
它的桅杆是如此吗?
如何使带有lambda函数的字典具有Func <>包含不同数量的参数?如何使带有lambda函数的字典具有不同数量的参数
Dictionary<string, Func<T, double>> operationsList
= new Dictionary<string, Func<T, double>>();
它的桅杆是如此吗?
你可以让你的字典式Delegate
,但我敢肯定,呼吁Func<>
这种方式存储将是一个痛苦:
var dict = new Dictionary<int, Delegate>();
dict.Add(1, (Func<int, int>)((int x) => x * 10));
dict.Add(2, (Func<int>)(() => 10));
呼叫:
var result1 = dict[1].DynamicInvoke(10);
var result2 = dict[2].DynamicInvoke();
如何返回值? – Zverit
你能一点点更具体一点,那还不是很清楚。 –
假设你做了,你会如何使用这样的字典? – Douglas
你不能。字典只存储一种类型。如果要存储异构对象,则必须使用“对象”或“动态”,然后转换为所需的类型。 –