here is my for loop code,
private bool setspinerotate = false;
private bool setspinerotate2 = false;
private bool setspinerotate3 = false;
void clearall()
{
bool[] checkjoint = {setspinerotate,setspinerotate2, setspinerotate3};
for (int a = 0; a < checkjoint.Length; a )
{
checkjoint[a] = true;
}
}
and I perform this function in another function, all the value is not turning to true
. Why?
CodePudding user response:
The way that you would make this work is to only ever use the array. Don't create individual variables.
Do it like this:
private bool[] _setSpineRotates = new[] { false, false, false };
void ClearAll()
{
for (int a = 0; a < _setSpineRotates.Length; a )
{
_setSpineRotates[a] = true;
}
}
NB: This has absolutely nothing to do with the difference between value-types versus reference-types. Both behave exactly the same in this circumstance.