I have some weird behaviour with a foreach-loop:
 IEnumerable<Compound> loadedCompounds;
 ...
 // Loop through the peaks.
 foreach (GCPeak p in peaks)
 {
     // Loop through the compounds.
     foreach (Compound c in loadedCompounds)
     {
         if (c.IsInRange(p) && c.SignalType == p.SignalType)
         {
             c.AddPeak(p);
         }  
     }
 }
So what I'd like to do: Loop through all the GCPeaks (it is a class) and sort them to their corresponding compounds.
AddPeak just adds the GCPeak to a SortedList. Code compiles and runs without exceptions, but the problem is:
After c.AddPeak(p) the SortedList in c contains the GCPeak (checked with Debugger), while the SortedLists in loadedCompounds remains empty.
I am quite confused with this bug I produced:
- What is the reason for this behavior? Both Compound and GCPeak are classes so I'd expect references and not copies of my objects and my code to work.
- How to do what I'd like to do properly?
EDIT:
This is how I obtain the IEnumarables (The whole thing is coming from an XML file - LINQ to XML). Compounds are obtained basically the same way.
 IEnumerable<GCPeak> peaksFromSignal = from p in signal.Descendants("IntegrationResults")
                                        select new GCPeak()
                                        {
                                            SignalType = signaltype,
                                            RunInformation = runInformation,
                                            RetentionTime = XmlConvert.ToDouble(p.Element("RetTime").Value),
                                            PeakArea = XmlConvert.ToDouble(p.Element("Area").Value),
                                        };
Thanks!
 
     
    