re: Challenge: Get Closest Number in an Array VIEW POST

FULL DISCUSSION
 

Here's some C# for everyone:

var nums = new int[] { 100, 200, 400, 800, 1600, 3200, 6400, 128000 };
var given_num = 900;

var result = 
    (
        from num in nums
        let diff = Math.Abs(given_num - num)
        orderby diff
        select num
    )
    .First();
code of conduct - report abuse