title: find the longest match of a string in list c#
body: <p>I have a list of string I need to find the longest match of my search string in the list.</p>
  
  <p>for example the list contains :  "test", "abc", "testing", "testingap" and my search string is  'testingapplication'</p>
  
  <p>the result should be 'testingap'</p>
  
  <p>here is what I did so far , it does the work but I'm looking is there any better efficient way to do this </p>
  
  <pre><code>string search= "testingapplication";
  List&lt;string&gt; names = new List&lt;string&gt;(new[] { "test", "abc", "testing", "testingap" });
  List&lt;string&gt; matchedItems = new List&lt;string&gt;();
  
  foreach (string item in names)
  {
          if (search.Contains(item))
          {
              matchedItems.Add(item);
              Console.WriteLine(item);
          } 
  }
  
  var WordMatch= matchedItems.Aggregate("", (max, cur) =&gt; max.Length &gt; cur.Length ? max : cur);
  Console.WriteLine("WordMatch"+WordMatch);
  </code></pre>