Am I not able to modify a variable in a structure that is in a list?

for (int player = 0; player < winners.Count; ++player) //some code that defines the boolean 'currenthighest' if (currenthighest) winners[player]._isWinner = true; 

winners is a list of GameResults,

GameResult is a structure that contains a number of other variables.

_isWinner is the boolean part of the GameResult structure.

As you can see, I am trying to change the boolean value of the structure in position 'player' of my list.

But it tells me no

Specifically "Cannot modify the return value of '<..Structs.GameResult>.this[int]' because it is not a variable"

Will I have to create the structure again and plug the whole thing back in to the list? Or is there some way I can modify just the boolean portion?

Furthermore, why isn't it recognizing that I am accessing the boolean portion, as I assume "is not a variable" means?

NOTE: there is a bunch more code for error proofing, such as making sure values even exist in the list. Just not included since the whole program would take up a lot of space here

by Strixxi via /r/csharp

Leave a Reply