Would adding an overload for a step size to Enumerable.Range
be too niche of a request?
#97790
tacosontitan
started this conversation in
Polls
Replies: 2 comments 2 replies
-
Not gonna lie, I've never thought about this being valid syntax. for (int currentValue = 0, step = 5, count = 1; Anyways.. given that this is all you need, and the use-case is so highly niche, I don't see them adding it. That said though, you can create your own struct with its own enumerator, so you can do something like this: foreach (var i in new MySteppyRange(0, 100, 5))
{} Which is not only less code (especially with a less dumb name), but it's also fully legal code already! |
Beta Was this translation helpful? Give feedback.
1 reply
-
If we did add it, I expect it would be as part of adding a generic range method: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on a project for code golf and I frequently use
Enumerable.Range
to generate data, but it's always lacked the ability to specify a custom step size. This leads to me using boilerplate like:It would be nice to simplify this to:
However, this seems like a pretty niche overload, which doesn't make it a solid proposal IMHO.
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions