replacing variable in elements of a List
<p>A more simple example might be:</p>

<pre><code>List &lt;myElement&gt; Elements;
Elements.Add(my1);
Elements.Add(my2);
</code></pre>

<p>my1 and my2 eache have a variable of type string named myString</p>

<p>Now I want to change the value of my1.myString. But if I change it the value my2.myString gets changed aswell.</p>

<p>Hopefully it's a bit clearer now</p>

<hr>

<p>I'm using a List with several Elements within it in C#. The List has as type a self-defined class with several variables in it.</p>

<p>Now I want to change in one list-element the value of a variable. But unfortunately the value gets replaced not only on this but in all elements of this list.</p>

<p>Any advice on how to fix this?</p>

<pre><code>MyProjectElement File1 = this.Project.Elements[0];
MyProjectElement File2 = this.Project.Elements[1];
MyProject my1 = (MyProject)File1;
MyProject my2 = (MyProject)File2;

PageCount_F1 = my1.PageCount;
PageCount_F2 = my2.PageCount;

if (PageCount_F1 != PageCount_F2)
MessageBox.Show("The 2 files need to have the same file length", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

else
{
my1.IncludeAllPages = false;
my2.IncludeAllPages = false;

for(int i=1; i &lt;= PageCount_F1; i++)
{
    StringBuilder value1 = new StringBuilder();
    StringBuilder value2 = new StringBuilder();
    value1.Append("" + i);
    value2.Append("" + (PageCount_F2-i+1));
    MyProject my1new = new MyProject();
    MyProject my2new = new MyProject();
    my1new.Pages = value1.ToString();
    my2new.Pages = value2.ToString();
    my1.Pages = my1new.Pages;
    my2.Pages = my2new.Pages;

    this.Project.Elements.Add((myProjectElement)my1);
    this.Project.Elements.Add((myProjectElement)my2);

    ((MyProject)this.Project.Elements[1]).Pages.Remove(0);
    ((MyProject)this.Project.Elements[i]).Pages.Remove(0);
    ((MyProject)this.Project.Elements[1]).Pages = "" + 1;
    ((MyProject)this.Project.Elements[PageCount_F2 - i + 1]).Pages = "" + (PageCount_F2 - i + 1);

    ((MyProject)this.Project.Elements[i-1]).Pages.Remove(0);
    ((MyProject)this.Project.Elements[i]).Pages.Remove(0);
    ((MyProject)this.Project.Elements[i - 1]).Pages = "" + i;
    ((MyProject)this.Project.Elements[i]).Pages = "" + (PageCount_F2 - i + 1);
}            
</code></pre>
