You could implement finding a match using a for-loop:
private List<string> LoopFindExactMatch(List<List<string>> listolists, string matchtofind)
{
foreach(var listostring in listolists)
{
if(listostring.Contains(matchtofind))
{
return listostring;
}
}
return null;
Or, you could use Linq to simplify the code:
using System.Linq
private List<string> LinqFindExactMatch(List<List<string>> listolists, string matchtofind)
{
return listolists.FirstOrDefault(ll => ll.Contains(matchtofind));
}
Test:
private void testFindMatch()
{
List<string> list1 = new List<string> { "a", "b", "c" };
List<string> list2 = new List<string> { "d", "e", "f" };
List<string> list3 = new List<string> { "g", "h", "k" };
List<List<string>> ListOLists = new List<List<string>> {list1, list2, list3};
List<string> result1 = LoopFindExactMatch(ListOLists, "d");
List<string> result2 = LinqFindExactMatch(ListOLists, "d");
List<string> result3 = LoopFindExactMatch(ListOLists, "x");
List<string> result4 = LinqFindExactMatch(ListOLists, "y");
}
Note that in these examples we search for only the first match. If your list of lists contains 'inner' lists with duplicate values, another strategy is indicated.