I have two string arrays; one is list and the other is find
I want to be able to count the number of items in find that are partially contained within ‘list’ using extension methods and linq. Here is a summary of how I would do it within a few nested loops:
int Count = 0;
foreach (string f in find)
{
foreach (string l in list)
{
if (l.Contains(f))
{
Count++;
break;
}
}
}
return Count;
I’d like to be able to do something like:
int Count = list.Select(...);
In my actual application, list is an element within a linq query of type IQueryable<string> and find is a static string[]. I’d like to be able to perform the count above within linq. I know I will probably have to use .AsEnumerable() as whatever the solution is probably wont be able to be translated to SQL.
1 Answer