Resharper removes yield from foreach. Why?
I recently learned about
Yet I noticed Resharper wants to convert my
Why does Resharper want to remove yield from this case? It changes the functionality completely as it will no longer lazy load without yield. I can only guess that either
Any insight would be great.
You are correct that this proposed transformation changes the functionality of the code in subtle ways, preventing it from deferring the evaluation of the properties and performing the
Perhaps those that implemented it were well aware that it was a change in functionality and felt that it was still a useful suggestion, one that could be ignored if the existing semantics were important, or if they actually failed to realize that the semantics were being altered. There’s no good way for us to know, we can only guess. If those semantics are important for your program, then you are correct to not make the suggested transformation.