Without LINQ, you can use a for loop to iterate through the list and keep track of the closest number. You can initialize a variable to store the closest number and the difference between the input number and the current list item, then update it every time a number closer to the input number is found. Here is an example:
List<int> list = new List<int> { 4, 2, 10, 7 };
int number = 5;
int closest = list[0];
int difference = Math.Abs(number - closest);
for (int i = 1; i < list.Count; i++)
{
int currentDifference = Math.Abs(number - list[i]);
if (currentDifference < difference)
{
closest = list[i];
difference = currentDifference;
}
}
In this example, the variable closest will contain the closest number to the input number.