开发者

most efficient way to find largest of three doubles in .NET Microframework?

开发者 https://www.devze.com 2023-01-16 16:06 出处:网络
I have three doubles: double[] accel = ne开发者_Python百科w double[3] { _Razor.Accel_X, _Razor.Accel_Y,

I have three doubles:

double[] accel = ne开发者_Python百科w 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?


double result = accel[0];
if (accel[1] > result) result = accel[1];
if (accel[2] > result) result = accel[2];
return result;


i believe it is the usual way.

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


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号