Session object changes when object is updated in C#

后端 未结 6 1437
执笔经年
执笔经年 2020-12-11 05:28

I have this really weird problem and I\'m sure I\'m missing something obvious here. I have these two lines:

HttpContext.Current.Session[listModelType + \"Lis         


        
6条回答
  •  被撕碎了的回忆
    2020-12-11 05:52

    In the first example your session variable is pointing to a reference so it gets updated because the two references are pointing to the same value.

    The second session variable is pointing to a primitive (value) type so they have separate copies of value.

提交回复
热议问题