views:

89

answers:

4

I have three doubles:

double[] accel = new double[3]
        {
            _Razor.Accel_X,
            _Razor.Accel_Y,
            _Razor.Accel_Z,
        };

What's the most efficient way to find the largest of these in NETMF?

+4  A: 
double result = accel[0];
if (accel[1] > result) result = accel[1];
if (accel[2] > result) result = accel[2];
return result;
dtb
A: 

Probably just this, right?

double max = _Razor.Accel_X;

if (_Razor.Accel_Y > max)
    max = _Razor.Accel_Y;

if (_Razor.Accel_Z > max)
    max = _Razor.Accel_Z;

Or did you want something prettier?

Dan Tao
+2  A: 

i believe it is the usual way.

double max = max((max(accel[0],accel[1]),accel[2])

Arthur Rizzo
Do you really think its a good idea to name your variables (max) the same as the macro max?
semaj
A: 

The shortest solution with LINQ: accel.Max();

BlueCode
he talks about the "Microframework" ;) there is NO Linq
chriszero