Paul
Paul

Reputation: 3954

C# Linq query to find strings in an array that end with strings in another array

I have two lists of strings in a C# program. One is a list of valid strings, the other is a list of directories:

string[] allDirs = Directory.GetDirectories(path);
string[] validEndings = new string[] { "ABC", "DEF" };  // for example

How can I write a Linq statement to get just the string values in allDirs that end with any one of the values in validEndings?

Upvotes: 1

Views: 876

Answers (1)

ingvar
ingvar

Reputation: 4377

allDirs.Where(d => validEndings.Any(d.EndsWith));

Upvotes: 4

Related Questions