Can anyone explain this behavior?
this code work:
Dictionary<string, int> fullPathTabAssociation = new Dictionary<string, int>();
//bla bla..
//here fullPathTabAssociation is populated
////bla bla..
var newValues = fullPathTabAssociation
.Where(x => x.Value > index)
.Select(x => new KeyValuePair<string, int>(x.Key, x.Value - 1))
.ToList();
fullPathTabAssociation.Clear();
/*now newValues is populated with correct values*/
this code doesn't work
Dictionary<string, int> fullPathTabAssociation = new Dictionary<string, int>();
//bla bla..
//here fullPathTabAssociation is populated
////bla bla..
var newValues = fullPathTabAssociation
.Where(x => x.Value > index)
.Select(x => new KeyValuePair<string, int>(x.Key, x.Value - 1))
fullPathTabAssociation.Clear();
/*now newValues is empty*/
The select function seems return a new IEnumerable
, with the debug before fullPathTabAssociation.Clear()
in both cases the values is correct for newValues
and are different from fullPathTabAssociation
. Specially I do not understand what happens in the last case