我想找到這個元素的最接近值之間的範圍。 元素之間的增量值。這將是正數,因爲它的模數。如何找到數組中每個元素的最近值?
class Element {
double DeltaValue;
double ElementValue;
public Element(double n) {
ElementValue = n;
}
static void Main() {
list<Element> ListElements = new list<Elements>;
ListElements.Add(3);
ListElements.Add(10);
ListElements.Add(43);
ListElements.Add(100);
ListElements.Add(30);
ListElements.Add(140);
for(int i = 0; i < ListElements.Count; i++) {
ListElements[i].DeltaValue = //and problem is here
//example as for ListElements[2].DeltaValue will be 13; because 43-30=13;
}
//示例如ListElements [2] .DeltaValue將爲13;因爲43-30 = 13;
你有沒有想過對數組進行排序? –
@ Sidias-Korrado不,我從來沒有使用過它 – ldn