I have a dictionary of type Dictionary<string, IEnumerable<string>>
and a list of string values. For some reason, every time I do Add, every value in the dictionary is overwritten. I am completely at a dead end why this is happening. I made sure that this is not a reference problem, which is to declare and initialize an IEnumberable object in a loop, so that it does not go beyond a single iteration, and it still does. Here is my code:
foreach (string type in typelist) { IEnumerable<string> lst = from row in root.Descendants() where row.Attribute("serial").Value.Substring(0, 3).Equals(type) select row.Attribute("serial").Value.Substring(3).ToLower(); serialLists.Add(type, lst); }
where typelist
is IEnumerable<string>
, root
is XElement
, and serialLists
is my Dictionary.
source share