在获得特定值后获取列表的一部分

Woj*_*icz 0 c#

我有一个简单的问题我有一个列表:

List<string> test = new List<string> {"one", "two", "three", "four"}
Run Code Online (Sandbox Code Playgroud)

现在我想以"三"为例,并获取其后的所有元素,因此它看起来像:

List<string> test = new List<string> {"three", "four"}
Run Code Online (Sandbox Code Playgroud)

但我们不知道列表的末尾,因此它可以是许多元素的列表,我们不能将end定义为const.

可能吗?

Jon*_*eet 8

听起来你正在寻找SkipWhileLINQ:

test = test.SkipWhile(x => x != "three").ToList();
Run Code Online (Sandbox Code Playgroud)

这将跳过所有内容,直到(但不包括)"三"值,然后包含其他所有内容.然后它再次将其转换为列表.