title: How to do a comparison function in C#
body: <p>Say I have elements (X, Y, and Z) in a list, I have a function, that generates a percentage, of how much two objects resemble each other. </p>
  
  <p>What I want to do, is run X against Y and Z using my compareElements, so:</p>
  
  <pre><code>compareElements(X,Y); // equals 55
  compareElements(X,Z); // equals 60
  </code></pre>
  
  <p>Then Y against X and Z</p>
  
  <pre><code>compareElements(Y,X); // equals 55
  compareElements(Y,Z); // equals 62
  </code></pre>
  
  <p>Then Z against Y and X</p>
  
  <pre><code>compareElements(Z,X); // equals 60
  compareElements(Z,Y); // equals 62
  </code></pre>
  
  <p>Then, I return the highest value, which is 62.</p>
  
  <p>Obviously, there's some repetition there, I don't need the repetition, but I'm not sure how to eliminate it. </p>
  
  <p>How do I structure my LINQ query, or a function/algorithm to do this comparison on every element, without the repetition?</p>
  
  <p>I'd prefer to use LINQ if I can, as I'm being passed an enumerable and the function returns before the list is actually enumerated, so we can save the cost of performing the compare, until the list is enumerated.</p>
  
  <p>All I need is that highest value, of the compare functions, 62.</p>
  
  <p>Note: <em>My actual result set I'm working with averages between 3 and 10 elements in the list, that need to be ran through this compare function.</em></p>