Suppose I have this number list:
List = new List(){3,5,8,11,12,13,14,21}
Suppose that I want to get the closest number th
This is my answer
List myList = new List() { 3, 5, 8, 11, 12, 13, 14, 21 }; int n = 11; int? smallerNumberCloseToInput = (from n1 in myList where n1 < n orderby n1 descending select n1).First(); int? largerNumberCloseToInput = (from n1 in myList where n1 > n orderby n1 ascending select n1).First();