I think i did understand you correctly, you request two numbers not one, basing the second one in the first result, but using the same list (without the found item); you can do the next:
public static void Main()
{
double number1 = 0;
var listQ = new List<double>() {1, 3, 3.2, 4, 4.1 ,5};
double i = 3.5;
number1 = listQ.FindClosest(i); //this is what you have
//the where will exclude the number just found, and search based on that number.
double number2 = listQ.Where(a=>a!=number1).FindClosest(number1);
Console.WriteLine("item " +number1 + "Item 2: " + number2);
}
begin FindClosest
an extension method:
public static class ListDoubleExtensions
{
public static double FindClosest(this IEnumerable<double> listQ, double number)
{
return listQ.Aggregate((x, y) => Math.Abs(x - number) < Math.Abs(y - number) ? x : y);
}
}
UPDATE after OP's comment
It is not fully clear what you are looking for, but run it on a loop should do the job:
public static void Main()
{
double number1 = 0;
var listQ = new List<double>() {1, 3, 3.2, 4, 4.1 ,5};
double i = 3.5;
int loops = listQ.Count();
double previousNumber = i;
for(int iterator = 0; iterator<loops; iterator++){
number1 = listQ.FindClosest(previousNumber); //this is what you have
listQ = listQ.RemoveFromList(number1);
Console.WriteLine("item " +number1);
previousNumber = number1;
}
}
then you need to add another extension method to remove the element from the list
public static class ListDoubleExtensions
{
public static double FindClosest(this IEnumerable<double> listQ, double number)
{
return listQ.Aggregate((x, y) => Math.Abs(x - number) < Math.Abs(y - number) ? x : y);
}
public static List<double> RemoveFromList(this List<double> listQ, double number)
{
return listQ.Where(a=>a!=number).ToList();
}
}
fiddle: https://dotnetfiddle.net/