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

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

saleItems = new List  ();
         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 13:59

    As it is a reference type, just the pointer to the values in memory is copied not the values themselves. You can specifiy the behaviour you want with a constructor:

    From dot net perls: // // Copy the Dictionary to a second object. // Dictionary copy = new Dictionary(dictionary);

提交回复
热议问题