title: Distance between two values
body: <p>I have a array</p>
  
  <pre><code>int[] Values = new int[] { 5, 43, 45, 25, 16, 89, 65, 36, 62 };
  </code></pre>
  
  <p>and currently i am calculating the maximum distance between all values <code>84 = 89 - 5</code></p>
  
  <pre><code>int MaxDistance = Values.SelectMany((a) =&gt; Values.Select((b) =&gt; Math.Abs(a - b))).Max();
  </code></pre>
  
  <p>now I want to calculate the minimum distance <code>2 = 45 - 43</code></p>
  
  <p>@ycsun's commment - this doesn't work</p>
  
  <pre><code>int MinDistancee = Values.SelectMany((ia, a) =&gt; Values.Select((ib, b) =&gt; ib == ia ? int.MaxValue : Math.Abs(a - b))).Min();
  </code></pre>