© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
Sound

❔ Foreach

in c++ i can do :
auto objects = std::vector<Object>();
for(auto& obj : objects) {...} // here i can modify obj (move, remove etc)
for(auto obj : objects) {...} // here i can't move/delete obj from objects
auto objects = std::vector<Object>();
for(auto& obj : objects) {...} // here i can modify obj (move, remove etc)
for(auto obj : objects) {...} // here i can't move/delete obj from objects


From what i know, in C# this doesn t allow me to remove, move, modify objects.
var objects = new List<Object>();
foreach(var obj in objects) {...}
var objects = new List<Object>();
foreach(var obj in objects) {...}


How can i do something like this
for(auto& obj : objects)
for(auto& obj : objects)
without having to use indices?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Remove Foreach
C#CC# / help
3y ago
❔ Foreach loop
C#CC# / help
4y ago
✅ Foreach vs Parallel.ForEach with Async mehtods
C#CC# / help
4y ago