I've been reading up extensively on structs, and I have a decent understanding of where you would use them. One thing though bothers me is, no matter how much i read about it, I don't understand the immutability of structs.
I understand that, like strings, if you change them you essentially create an entirely new object in memory, but does this also hold for the values inside a struct. For instance:
public struct SomeValues
{
public int AnInt;
public float AFloat;
public string AString;
}
public SomeValues[] ArrayOfValues;
private void SomeFunctionThatRunsContinuously()
{
/*so for every value I change, do I essentially create a whole new instance
of SomeValues?*/
for (int i = 0; i < ArrayOfValues.Length; i++)
{
//Is this another struct?
ArrayOfValues[i].AnInt++;
//And then another again?
ArrayOfValues[i].AFloat += 0.33f;
/*I realise adding letters to a string is a horrible idea
-- but is it WORSE to do it in a struct?*/
ArrayOfValues[i].AString += "s";
}
}
So for instance, if I had a struct which for instance was holding the coordinates of every person inside a 3D/2D space (coordinates were given as an example of when to use structs), and the positions of the people change and are updated inside a two/three int struct, from maybe an array, is that creating new structs because they're immutable?