title: Get closest value in an Array
body: <pre><code>int [] testArray = new int[3] { 5, 7, 8};
  
  int check = 22;
  
  var nearest = testArray.Min(x =&gt; Math.Abs(x - check));
  
  Debug.Print(Convert.ToString(nearest));
  </code></pre>
  
  <p>I have the above code as an attempt to try and get the nearest number in the array closest to the check number, in this case 22.</p>
  
  <p>The thing is that this always returns a positive value because of the Math.Abs but if I remove this the code completely fails. for example if the check number is 10, i want nearest to return -2 and not 2. This way I can just add the nearest value to the check number to get the proper value that's in the array.</p>
  
  <p>I found something similiar upon searching, something called MoreLinq, that suggested using array.MinBy instead, however this method throws an error (says it doesn't exist)... Thanks</p>