Having trouble wrapping my head around the concept of modifying these two different lists. So when using a regular for loop to iterate over each one, we can directly modify the list of integers, but cannot modify a specific item in the list of ValueTuples.
Consider this example
var test = new List<int>() { 1, 2, 3, 4 };
for (int i = 0; i < test.Count; i++)
{
test[i] += 1;
}
var test2 = new List<(int, int)>() { (1, 2), (2, 3), (3, 4) };
for(int i = 0; i < test2.Count; i++)
{
test2[i].Item1 += 1;
}
So in this, we can successfully add 1 to each integer value in the first list. However, with the second list we actually get a compiler error of CS1612 which states "Cannot modify the return value of 'List<(int, int)>.this[int]' because it is not a variable."
I read into the error on the official docs, and it makes sense that in the second example we are returning a copy of the ValueTuple, therefore we are not modifying the actual one in the list. But then why does the integer example work?
Feel like I might just be overcomplicating this, but wanted to ask here and see where I could be going wrong.