If you just need the min/max, and depthData
is a byte array of 16 bit depth values, this would be easier and faster:
int min = int.MaxValue, max = int.MinValue;
for( int i = 0; i < depthData.Length; i += 2 )
{
int dist = GetDistance( depthData[i], depthData[i + 1] );
if( dist < min ) min = dist;
if( dist > max ) max = dist;
}
Using that depthIndex
variable that seems to be declared somewhere else looks dangerous. And the list is just redundant!