I have a class
public class VitalSign
{
public double? Temprature { get; set; }
public double? SystolicBP { get; set; }
public double? DiastolicBP { get; set; }
public double? PulseRate { get; set; }
public double? Respirations { get; set; }
}
and a Range class
public class VitalRange
{
public Tuple<double,double> TemperatureRange { get; set; }
public Tuple<double, double> SystolicBPRange { get; set; }
public Tuple<double, double> DiastolicBPRange { get; set; }
public Tuple<double, double> RespirationsRange { get; set; }
public Tuple<double, double> PulseRange { get; set; }
}
I have to compare if my property(say temperature) is out of range compared to VitalRange( Temperature). Can I use a Tuple in this case or can I have a KVP for ranges?. I will be comparing a huge List against VitalRange. What will be the fastest way to check if a property falls within the range.?
I don't know what's your problem, It's simple if
, but you can encapsulate it by using extension methods:
public static bool IsInRange(this double? input, Tuple<double, double> range)
{
if (!input.HasValue)
return false;
return input >= range.Item1 && input <= range.Item2;
}
and use it like this:
VitalRange sampleRanges = ....;
var validTempers = vitalSignList.Where(x=>x.Temprature.IsInRange(sampleRange.VitalRange);
I can't think for extremely faster way, but I prefer encapsulation.