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

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

saleItems = new List  ();
         


        
6条回答
  •  我在风中等你
    2020-11-30 14:00

    The dictionary contains the same reference to the list, so modifying the list will change both references.

    Microsoft documentation about reference types: http://msdn.microsoft.com/en-us/library/490f96s2.aspx

提交回复
热议问题