I have a question on this program. It does not produce the correct result. I assume that it should give me output like + 1 + 2 - 1 + 3 - 2 + 4 - 3 + 5 - 4 - 5 (not order specific). However, it outputs + 1 + 2 - 2 + 3 - 3 + 4 - 4 + 5 - 5 - 5.
If I make a copy
MyStructure msCopy = ms;
Thread t = new Thread(() => { updateMe(msCopy); });
It outputs the correct value. I am using .net 3.5. What is the reason?
class Program
{
    static void Main(string[] args)
    {
        Program p = new Program();
        p.createThread();
    }
    List<MyStructure> structure = new List<MyStructure>();
    public void createThread()
    {
        foreach (MyStructure ms in structure)
        {
            System.Diagnostics.Debug.WriteLine("+ " + ms.ID);
            //MyStructure msCopy = ms;
            //Thread t = new Thread(() => { updateMe(msCopy); });
            Thread t = new Thread(() => { updateMe(ms); });
            t.Start();
        }
    }
    private void updateMe(MyStructure ms)
    {
        System.Diagnostics.Debug.WriteLine("- " + ms.ID);
    }
    public Program()
    {
        structure.Add(new MyStructure { ID = 1, Name = "A" });
        structure.Add(new MyStructure { ID = 2, Name = "B" });
        structure.Add(new MyStructure { ID = 3, Name = "C" });
        structure.Add(new MyStructure { ID = 4, Name = "D" });
        structure.Add(new MyStructure { ID = 5, Name = "E" });
    }
}
internal class MyStructure
{
    public int ID { get; set; }
    public String Name { get; set; }
}
 
    