title: Finding the most specific matching item
body: <p>User input will be like 'BY1 2PX', which will split and stored into list like below</p>
  
  <pre><code>var items = new List&lt;string&gt; {'BY1 2PX', 'BY12', 'BY1', 'BY'};
  </code></pre>
  
  <p>I have source list of Products</p>
  
  <pre><code>public class Product
  {
      public string Name {get;set;}
      public string Id {get;set;}
  }
  </code></pre>
  
  <p>Below is a sample product list. There is no  guarentee on ordering, it could be in any order.</p>
  
  <pre><code>var products = new List&lt;Product&gt;{ 
      new Product("1", "BY1 2PX"),
      new Product("2", "BY12"),
      new Product("3", "BY1"),
      new Product("4", "BY"),
      new Product("5", "AA2 B2X"),
      //...etc
  }
  </code></pre>
  
  <p>my output should fetch 1, because its most specific match. If Id = 1 is not there then it should have fetched Id =2 like that...etc Could anyone help me in writing a linq query. I have tried something like below, is this fine?</p>
  
  <pre><code>var result =  items.Select(x =&gt; products.FirstOrDefault(p =&gt;
                        string.Equals(p.Name.Trim(), x, StringComparison.OrdinalIgnoreCase)))
                     .FirstOrDefault();
  </code></pre>