我不確定如何在字典上使用擴展方法。我如何指定我需要將函數應用於值而不是密鑰?在字典上使用擴展方法
下面是一個示例代碼,將雙精度擴展方法應用於雙精度值和雙精度值的字典。列表擴展方法工作正常,但字典擴展方法要求選擇器功能。
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();
}