Find substring in a list of strings

With Linq, just retrieving the first result:

string result = list.FirstOrDefault(s => s.Contains(srch));

To do this w/o Linq (e.g. for earlier .NET version such as .NET 2.0) you can use List<T>‘s FindAll method, which in this case would return all items in the list that contain the search term:

var resultList = list.FindAll(delegate(string s) { return s.Contains(srch); });

Leave a Comment