Enumerate through a subset of a Collection in C#?

后端 未结 6 1476
粉色の甜心
粉色の甜心 2021-02-08 01:12

Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I\'d like to enumerate

6条回答
  •  灰色年华
    2021-02-08 01:37

    I like to keep it simple (if you don't necessarily need the enumerator):

    for (int i = 249; i < Math.Min(340, list.Count); i++)
    {
        // do something with list[i]
    }
    

提交回复
热议问题