Sometimes, during development phase, I need to see if e.g. a name is changed for each element created or just wish to differentiate between different instances' names in an array. That behavior is strictly for development-stage and only to be applied during a short period of time (hence no need to long term solution - Q&D is just fine).
Usually, I introduce a counter in the following way but it just stroke me that there might be a better way. Basically, I wish to emulate behavior of the counter variable of for without actually introducing it (staying at foreach).
int counter = 1;
IEnumerable<Typo> result = originals.Select(original
=> new Thingy { Name = "Hazaa" + counter++ });
Use this overload of Select
IEnumerable<Typo> result = originals.Select((original, counter)
=> new Thingy { Name = "Hazaa" + (counter + 1) });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With