The alternative syntax that I prefer for @Henk's solution is this.
DateTime[] dates = new DateTime[10]; foreach(int index in Enumerable.Range(0, dates.Length)) { ref DateTime date = ref dates[index];
If you are doing a reasonable amount of work in a loop, then no need to repeat indexing everywhere easier on the eyes of imo.
PS DateTime is a really very bad example, since it does not have any properties that you can set, but you get an image.
Neutrino Nov 29 '17 at 15:53 2017-11-29 15:53
source share