我可以只选择前十行​​,也可以跳过foreach的前十行吗?

时间:2018-11-21 08:38:44

标签: c#

我正在运行这样的过程:

bins valid_commands[] = {[0:$] inside my_valid_commands};

此例程中的代码需要很长时间,我想做的是在前十行中运行它,然后在其余行中再次运行它。像这样:

foreach (var x in App.cardSetWithWordCount.Select((r, i) => 
      new { Row = r, Index = i }))
{
            // Some code here
}

然后

// just the first ten rows in App.cardSetWithWordCount
foreach (var x in App.cardSetWithWordCount.Select((r, i) => 
      new { Row = r, Index = i }))
{
            // Some code here
}

有没有一种方法可以只选择前十行​​,也可以跳过可以应用到foreach的前十行?

1 个答案:

答案 0 :(得分:3)

您可以使用

App.cardSetWithWordCount.Take(10)

要获取前10个,然后

App.cardSetWithWordCount.Skip(10)

跳过前十个

或者我想您可以使用老式的方法,通过for循环遍历App.cardSetWithWordCount。