Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# Sum of all the factors of a number 
Csharp :: c# dictionary check if value exists 
Csharp :: c# lambda group by multiple columns 
Csharp :: c# mongodb count documents 
Csharp :: remove empty strings from list c# 
Csharp :: button event trigger wpf 
Csharp :: Reading emails from Gmail in C# 
Csharp :: c# press ctrl and alt 
Csharp :: c# trimend substring 
Csharp :: entityframework index 
Csharp :: unity vector3 initialization 
Csharp :: vb.net windows version check 
Csharp :: DataGridView ComboBox column selection changed event 
Csharp :: get gameobject layermask 
Csharp :: check if element in hashset c# 
Csharp :: convert date to days c# 
Csharp :: the underlying connection was closed nuget 
Csharp :: how to get properties from json in c# 
Csharp :: convert list of string to dictionary 
Csharp :: is narcissistic number 
Csharp :: c# 2d arrays 
Csharp :: convert xml to json 
Csharp :: longest palindromic substring 
Csharp :: combined 2 arrays 
Csharp :: f# get last element of list 
Csharp :: cefsharp print 
Csharp :: remove numericUpDown white space 
Csharp :: no cameras rendering unity 
Csharp :: Handling Collisions unity 
Csharp :: how to refresh the data table in C# window form datagridview 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =