but in case when we are modifying copied object we might noticed that session object gets updated automatically,
the reason is both copied object and session object are pointing to same location,
even if you tried to use "new" operator while creating object.
|
|
Now, while accessing session object, you can call clone method to make copy of session.
Employee newEmployee = new Employee();
newEmployee = ((Employee) Session["EmployeeObj"]).clone();
now if you try to modify object copied from session, will not update session object.
newEmployee.Emp_FName = "Kapil"; //Will not update session employee FirstName

Join the conversation! Your thoughts help the community grow.