Here's my code:
Event thisEvent = (from i in list
where (i.eventID == eventID)
select i).FirstOrDefault();
if (thisEvent != null)
{
thisEvent.eventResolved = resolved;
thisEvent.eventSequence.Add(item);
}
"list" is a collection of IEnumerable, i.e.
IEnumerable<Event> list;
What I'm wondering is: after creating thisEvent using FirstOrDefault, is thisEvent still connected to list? In other words, when I change the two properties, eventResolved and eventSequence, is "list" actually changed, or is thisEvent just some totally disconnected copy of an item in "list"?
FirstOrDefault
selects an item in a collection, but does not "detatch" or "clone" it. I.e. it is the same instance. So if you modify a property you modify the original instance.
If you want to "detatch" the object you will have to copy it in some way or the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With