我有以下代码:
List<string> result = new List<string>();
foreach (string file in Directory.EnumerateFiles(path,"*.*",
SearchOption.AllDirectories)
.Where(s => s.EndsWith(".mp3") || s.EndsWith(".wma")))
{
result.Add(file);
}
它工作正常,可以满足我的需求。除了一件小事。我想找到一种更好的方法来过滤多个扩展。我想使用带有这样的过滤器的字符串数组:
string[] extensions = { "*.mp3", "*.wma", "*.mp4", "*.wav" };
使用NET Framework 4.0 / LINQ进行此操作的最有效方法是什么?有什么建议么?
我非常感谢偶尔的程序员提供的帮助:-)