Why can't I directly change the value of a list element?

I get a seriously frustrating message that I cannot change the values in a List this way:

for( int i = 0; i < myList.Count; i++ )
myList*.value = something;*
am I doing something wrong?
error CS1612: Cannot modify a value type return value of `System.Collections.Generic.List.this[int]'. Consider storing the value in a temporary variable

A List of structs cannot be updated like that - the reason is that structs are copied by value and are not a reference - so when you do .value you are changing a value on the copy which is then immediately discarded. If the items in the list were classes then this wouldn’t be the case because you would have a reference to the actual object. When working with structs you need to get the contents of the list item - modify it and then put it back again.

var v = myList*;*

v.value = something;
myList = v;
This can make structs slower that classes - especially if the items in question will hang around for a while and therefore not contribute to a garbage collection cycle.

Value is a readonly property (It only has a “get” accessor). Generic list is of reference type so it holds reference to other value typed fields. What you can do is, you can set i directly to the value you wish.

for( int i = 0; i < myList.Count; i++ ) myList *= something;*

For more info, Nullable<T>.Value Property (System) | Microsoft Learn