tags:

views:

28

answers:

1

Hi,

I have the following LINQ query:

List<string> Types = (List<string>)Directory.GetFiles(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727")
                                   .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains("Microsoft"))
                                   .ToList<string>();

How could I modify this so it can only get the values stored in a collection, without writing another LINQ query (which I assume will impact performance?)?

Thanks

+1  A: 

Try this:

List<String> Types 
    = Directory.GetFiles(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727")
        .Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains("Microsoft"))   
        .Where(x => yourCollection.Contains(x))
        .ToList();
Andrew Hare