Iterate range #4155
Unanswered
einord
asked this question in
Language Ideas
Iterate range
#4155
Replies: 2 comments
-
This is already possible today. You just need an extension GetEnumerator method for System.Range |
Beta Was this translation helpful? Give feedback.
0 replies
-
See #3004 for existing discussion on this, too. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently there is no simple and clean way to iterate some code a set number of times.
This is useful when generating random strings, or creating data for testing and other things that should be done any set number of times.
Currently this can be done in multiple ways (each creates messy and unnecessarily harder code to read):
Since C# 8 it is possible to use the new range syntax with arrays (
myArray[1..10]
), and this similar syntax could easily be used for foreach iterations:This would make the code a lot cleaner, very easy to understand and perhaps this could also be used in combination with discards if the current range value is not important:
Everything is based on previously existing syntax and feels intuitive in the C# language.
Beta Was this translation helpful? Give feedback.
All reactions