I've got some odd behaviour in a foreach loop, could anybody explain why this occurs?
Simple class:
Simple set of loops:
If I inspect the data object after the condition is met, data.Selected is indeed set to true, but when I inspect the activeDataSet, none of the objects have the Selected property set to true.
Why are the changes to the content of the collection not being reflected within the collection itself? I need to access the collection from elsewhere after this has run, and the flags are never set, and it's not that the condition in this code is never true.
Regards,
Rob.
Simple class:
Code:
public class ImageBindingObject
{
public ImageInfo ImageInfo { get; set; }
public bool Selected { get; set; }
}
Code:
private void SelectData(IEnumerable<ImageInfo> selected)
{
foreach (var image in selected)
foreach (var data in activeDataSet)
if (image.RelativePath == data.ImageInfo.RelativePath)
data.Selected = true;
}
Why are the changes to the content of the collection not being reflected within the collection itself? I need to access the collection from elsewhere after this has run, and the flags are never set, and it's not that the condition in this code is never true.
Regards,
Rob.
Comment