Hi @mc ,
Thanks for reaching out.
IEnumerable<T> only describes how you read items, not how they are stored. It means you can iterate through the items, but you can’t add, remove, or replace elements in the collection itself.
However, in your case, XY is a class (a reference type). That means the objects inside the IEnumerable<XY> are real instances, not copies. So while you can’t change the collection, you can safely modify the properties of each XY object.
You don’t need to convert it to an array or list just to update X. A simple iteration is enough:
foreach (var xy in xys)
{
xy.X += 1;
}
Converting to an array with ToArray() only makes sense if you need indexed access or want to change which elements are in the collection. For just updating properties, it adds unnecessary overhead.
The only time this would not work is if XY were a struct. In that case, each iteration would give you a copy, and changes wouldn’t persist. Since XY is a class here, you’re good.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.