粗略地说,插入一个数组:
double[] data = LoadData();
double requestedIndex = /* set to the index you want - e.g. 1.25 to interpolate between values at data[1] and data[2] */;
int previousIndex = (int)requestedIndex; // in example, would be 1
int nextIndex = previousIndex + 1; // in example, would be 2
double factor = requestedIndex - (double)previousIndex; // in example, would be 0.25
// in example, this would give 75% of data[1] plus 25% of data[2]
double result = (data[previousIndex] * (1.0 - factor)) + (data[nextIndex] * factor);
Run Code Online (Sandbox Code Playgroud)
这实际上是伪代码;它不执行范围检查,假设您的数据位于带有索引器的对象或数组中,等等。
希望这有助于您入门 - 如有任何问题,请发表评论。