Answers for "how to round to nearest number in array c#"

C#
0

how to round to nearest number in array c#

int[] array = {5,7,8,15,20};
int TargetNumber = 13;

var nearest = array.OrderBy(x => Math.Abs((long) x - targetNumber)).First();

//output = 15
Posted by: Guest on August-03-2021

Code answers related to "how to round to nearest number in array c#"

C# Answers by Framework

Browse Popular Code Answers by Language