我想知道我的以下代码是否有更好的替代方案(最好使用 LINQ)
#region List and filter directories to only 3 levels deep
// List all subdirectories within main directory
string[] folders = Directory.GetDirectories(@"C:\pdftest\", "*" ,SearchOption.AllDirectories);
List<string> subdirectories = new List<string>();
//Filter away all main directories, now we are left with subdirectories 3 levels deep
for (int i = 0; i<folders.Length; i++)
{
int occurences = folders[i].Split('\\').Length-1;
if (occurences==4)
subdirectories.Add(folders[i]);
}
#endregion