: create a copy of the value that is currently present in one particular iteration of the `foreach` by creating a function literal that takes your `struct` as a paramter. This works because structs are value types, so passing it to the function creates a copy.
Thanks, your solution seems to be the most elegant one yet, I recently came across the similar problem and I realized that the other answer was too long and verbose.