Problem is, you're returning reference to the same variable all the time:
ProcessorInfo result = new ProcessorInfo();
That's the only place you're actually creating new ProcessorInfo
object. You only change it's properties values later, but return still the same object.
You should consider adding copy constructor into your ProcessorInfo()
class, and replace every yield return result;
call with yield return new ProcessorInfo(result);
. That would be the easiest way to make it work.
Update
It could look like it works e.g. when you've saved some variable state somewhere during loop:
foreach(var item in query)
{
itemsList.Add(item);
propertyList.Add(item.IntProperty);
}
After that call itemsList
will contain incorrect data, while propertyList
will be just fine.