I have an array of elements. I want to find the lowest value from these elements but they have no property, I have to calculate the value and compare it first.
My pseudo code:
int currentLowestValue = int.MaxValue;
MyObj targetElement = null;
for (int i = 0; i < elements.Length; i++)
{
MyObj ele = elements[i];
int val = ele.CalculateValue() + GetOtherValue();
if (val < currentLowestValue)
{
targetElement = ele;
currentLowestValue = val;
}
}
How can I select the element with the lowest value calculated out of ele.CalculateValue() + GetOtherValue();
by using Linq?