Cannot assign to balance because it is a foreach iteration variable

148

Cannot assign to 'balance' because it is a 'foreach iteration variable' -

//foreach is a read only iterator that iterates dynamically classes that implement IEnumerable

//This is a possible solution
for (int i = 0; i < MyObjectList.Count; i++)
{
    MyObjectList[i] = new MyObject();
}

//or if you want to change only the fields:
foreach (var item in MyObjectList)
{
  item.Value = Value;
}

Comments

Submit
0 Comments