A certain API call is returning two arrays. One array contains Property names, e.g
Properties[0] = "Heartbeat"
Properties[1] = "Heartbeat 2"
Properties[2] = "Some Other discovery method"
Another array contains values for the Properties array, e.g
Values[0] = "22/01/2007"
Values[1] = "23/02/2007"
Values[2] = "5/06/2008"
The values and properties array elements match up, e.g Values[0] is always the value of Properties[0], etc.
My aim is to get the most recent "Heartbeat*" value. Note that the Heartbeat properties and values are not always in elements 1 and 2 of the array, so I need to search through them.
Code looks like this:
static DateTime GetLatestHeartBeat(string[] Properties, string[] Values)
{
DateTime latestDateTime = new DateTime();
for(int i = 0; i < Properties.Length; i++)
{
if(Properties[i].Contains("Heart"))
{
DateTime currentDateTime;
DateTime.TryParse(Values[i],out currentDateTime);
if (currentDateTime > LatestDateTime)
latestDateTime = currentDateTime;
}
}
return latestDateTime
}
The above code gives me the desired result, only issue being the loop continues after there are no more Heartbeat values to find. Is there a more efficient way of performing the above?