I am very confused as to why my foreach loop is not changing any of the code.
This is the code:
foreach (var device in job.JobDeviceTypes)
{
var location = (await _IDeviceService.GetDevicesInStorageByDeviceType(device.DeviceType.DeviceTypeId, job.TeamId)).ToList().Select(x => x.Location.LocalId0).Distinct().ToList();
device.Local_Id0 = location;
}
When running the code, the value of location and device.Local_Id0 are both changed. However, the actual set that is being iterated over (job.JobDeviceTypes) does not change. job is a public class whose member JobDeviceTypes is of type public IEnumerable
I have done some testing where I even ran: job.JobDeviceTypes.ToList()[0].Local_Id0.Add("0"); and the entry wasn't being added.
Jochen BartlauPosted Apr 25, 2022, 10:31 AM
This needs to be something very specific to the classes you're using. I tried to repro this with some simple/normal classes and it worked just fine. Are you able to clone this problem to a repo on Github or similar?