【发布时间】:2017-03-16 10:32:50
【问题描述】:
我想创建一个 C# 方法,该方法接受包含已知值和查询值的字典对象(例如,<int, double> 类型),以便可以从字典和查询值生成方程式被查找返回一个插值。
作为模拟:
public double ReturnValue(Dictionary<int, double>, int queryValue)
{
// Generates an equation (e.g. in the form of y = mx + c) based on the dictionary object values
// Looks up y based on queryValue as an input in the variable x
return y;
}
Creating dynamic formula - 这看起来像是我想要的,但对于我的情况来说似乎有点太复杂了。
感谢您的任何建议 - 谢谢。
更新:一个字典对象的例子:
var temperatureDic = new Dictionary<int, double>()
{
{ 0, 1.10},
{ 5, 1.06},
{ 10, 1.03 },
{ 15, 1.00 },
{ 20, 0.97 },
{ 25, 0.93 },
{ 30, 0.89 },
{ 35, 0.86 },
{ 40, 0.82 },
{ 45, 0.77 }
};
【问题讨论】:
标签: c# dictionary