Array range implementation. #4274
Replies: 3 comments 2 replies
-
It decreases readability, because weather the index is inclusive is unclear. With a method, the code reader can get clear understanding from the documentation of the method. |
Beta Was this translation helpful? Give feedback.
-
I also don't understand how does this improve the situation over a regular method with the same functionality. For example: int[] array = Ranges.Array(0, 5); // Result: 0, 1, 2, 3, 4, 5
int[] array = Ranges.Array(0, 5, step: 2); // Result: 0, 2, 4; the "step:" part is optional
char[] letters = Ranges.Array('A', 'Z'); I think it's not something that's used that often, so it doesn't need to be super succinct. |
Beta Was this translation helpful? Give feedback.
-
You can achieve similar code with extension methods: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I think it would be good to add a range implementation to C#. The return type is always a static array.
Suppose we define an array like this:
The description with the range I think of in my mind:
I think this could be an improvement that will make our work a lot easier in big definitions and different usage laws.
Likewise, if we want the range to increase by 2, for example, a derivative can be introduced as follows:
It can also be applied to char type:
I think it will be a good improvement in terms of readability and time savings. Please specify if you have a more logical syntax or idea. I think you understand the idea.
Beta Was this translation helpful? Give feedback.
All reactions