Making it happen
C# return reference types
| Print article | This entry was posted by andrei on March 18, 2008 at 2:40 pm, and is filed under Uncategorized. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 2 years ago
I agree. Having the option to return refs to structs would be nice, especially with collection indexers. I guess they haven’t allowed this because of issues of structs being stored on the stack.
about 2 years ago
Another situation where this is annoying is here:
vectors.ForEach(delegate(Vector2 c) { c.X = 4; c.Y = 2; });
Each element is copied as it’s passed as a parameter into the delegate, and it’s incorrect to write delegate(ref Vector2 c). The result is that vectors is not modified and you just spent a whole lot of time making garbage.