How to extract results from a list and use it with LinQ ?

  • Thread starter Thread starter Frankdot
  • Start date Start date
F

Frankdot

Guest
I have a list from a list:

List<double> alist = new List<double>() {xlist[y]};

for(int a = 0; a < alist.Count; a++)
{
alist[a] = (alist[a] + counter) / (someOtherInt - counter);

alist[a] is the result and return a series of number doubles like 1.23, 1.56, 1.65, etc.

Fibo is a variable that return a number changing when new data entering same as alist[a] . The result of Fibo can be for exemple 1.12.

I would like to find the closest number from Fibo.

I came up with:

List<double> list = new List<double>() { alist[a] };
var minDistance = list.Min(no => Math.Abs(fibo- no));
var closest = list.First(no => Math.Abs(fibo- no) == minDistance);
{
Print(closest);
}

Unfortunatly it appears i am performing a search on a single element list.

Print(closest); return all elements in the list and not the closest.

Its like the list is prisoner of the for loop. What ever i tried .Min or .Max, OrderBy it all return the entire list instead of a single number in this case the closest from fibo 1.23.

Any solution?

ty

Continue reading...
 
Back
Top