How do I set the statColor of a particle system through script

I am trying to set the startColor of a particle system through a script. I either get the error:

Cannot modify a value type return value of UnityEngine.ParticleSystem.main. Consider storing the value in a temporary variable

or

Property or indexer UnityEngine.ParticleSystem.main cannot be assigned to (it is read-only)

How do I do this please?

Implementation 1:

            foreach (ParticleSystem p in systemToChangeColor) {
                p.main.startColor = myColor;                
            }

Implementation 2:

            foreach (ParticleSystem p in systemToChangeColor) {
                ParticleSystem.MainModule newMain = p.main;
                newMain.startColor = myColor;
                p.main = newMain;
            }

@bhayward_incrowd try this.

foreach (ParticleSystem p in systemToChangeColor) {
     ParticleSystem.MainModule newMain = p.main;
     newMain.startColor = myColor;
}

@bhayward_incrowd Try this

foreach (ParticleSystem p in systemToChangeColor) {
    ParticleSystem.MainModule module = p.main;
    module.startColor = new ParticleSystem.MinMaxGradient(myColor);
}