I have the following code which does not compile cause of this error:
Error 5 Cannot modify the return value of 'System.Collections.Generic.List.this[int]' because it is not a variable
The code looks like this:
List<myStruct> myList = new List<myStruct> { new myStruct { a = 3 } };
myList[0].a = 5;
struct myStruct
{
public double a;
}
However when myStruct
is a class this compiles. I assume it has something to do with struct
being an immutable object whereas a class-instance is per se a "dynamic, mutable" object, maybe there are some better explenations for this.