private double?DecideTempValueToLookup(double temp, AmmoniaLookupTable table) { var tempValues = table.Cells.Select(x => x.Temp).OrderBy(x => x).ToList(); if (temp < tempValues.Min() || temp > tempValues.Max()) { return(null); } else { for (var i = 0; i < tempValues.Count; i++) { if (temp == tempValues[i]) { return(tempValues[i]); } if (temp > tempValues[i] && temp < tempValues[i + 1]) { return(tempValues[i + 1]); } } throw new ArgumentOutOfRangeException("System fails to decide temp value to look up for temp: " + temp); } }
private double?DecidePHValueToLookup(double ph, AmmoniaLookupTable table) { var phValues = table.Cells.Select(x => x.PH).OrderBy(x => x).ToList(); if (ph < phValues.Min() || ph > phValues.Max()) { return(null); } else { for (var i = 0; i < phValues.Count; i++) { if (ph == phValues[i]) { return(phValues[i]); } if (ph > phValues[i] && ph < phValues[i + 1]) { return(phValues[i + 1]); } } throw new ArgumentOutOfRangeException("System fails to decide PH value to look up for ph: " + ph); } }