Enumerable.Range - When does it make sense to use?

后端 未结 5 994
-上瘾入骨i
-上瘾入骨i 2021-02-07 23:02

When programming it\'s almost instinctive deciding when to use a for loop, or foreach, but what is the determining factors or problem space for choosing to use Enumerable.Range?

5条回答
  •  离开以前
    2021-02-07 23:52

    You can think about Enumerable.Range like a tool of retriveing subset of a collection.

    If content of collection are value types, you create also a new instance of every of them.

    Yes, you can do it with for loop, by setting correctly bounds of iteration, but thinking such way, almost all LINQ can be implemented in other ways (at the end it's just a library).

    But it have short, concise and clear syntax, that's why it's used so widely.

提交回复
热议问题