我有以下代码:
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 Framework4.0/LINQ执行此操作的最有效方式是什么?有什么建议吗?
如果能成为一名临时程序员,我将不胜感激:-)