C# dictionary value clearing out when I clear list previously assigned to it…why?

后端 未结 6 501
北恋
北恋 2020-11-30 13:25
Dictionary > saleItemNew = new Dictionary> ();

saleItems = new List  ();
         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 13:52

    Adding the List to the dictionary is just a shallow copy... A new list with the same values is not created and added (a deep copy); rather a reference to the old list is added.

提交回复
热议问题