跳到字符串并拿走其他项目

Skip to the string and take other items

我有文件夹段列表"c:\","user","temp","subfolder1","subfolder2" 我想找到 "temp" 项之后的所有项并加入它们。我已经使用两种方法解决了它:首先我找到了“temp”的索引,然后使用另一种 Linq 方法。

也许有一种 Skip 方法不仅接受索引而且接受名称? 像这样

directories.Skip("Temp").Skip(1).Take(1000)

我当前的代码

var findIndex = directories.FindIndex(f=>f.ToLower()=="temp");
if (findIndex != -1)
{
    filePath = string.Join(@"\", directories.Skip(findIndex).Skip(1).Take(1000));
}

您可以使用 SkipWhile:

directories.SkipWhile(x => x != "Temp").Skip(1).Take(1000)