我不确定如何在字典上使用扩展方法。我如何指定我需要将函数应用于值而不是密钥?在字典上使用扩展方法
下面是一个示例代码,将双精度扩展方法应用于双精度值和双精度值的字典。列表扩展方法工作正常,但字典扩展方法要求选择器功能。
static void Main(string[] args)
{
List<double> list = new List<double>();
list.Add(34.2);
list.Add(234);
Console.WriteLine(list.Sum());
Dictionary<string, double> dictioanary = new Dictionary<string, double>();
dictioanary.Add("a", 5.34);
dictioanary.Add("b", 44);
Console.WriteLine(dictioanary.Sum());
Console.ReadKey();
}