Re: Working with Cache and Viewstate

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hey David,

Thanks for the reply. That does make sense. I don't see a point in my work where I would need to do that, but it was interesting to find out it did that... and I wanted to know why.

Thanks :D

/RT
David Lloyd wrote:
Ryan:

The ArrayList class inherits from System.Object with means it is a reference type. When you set the value of the ViewState variable, I believe you are passing a reference to the underlying ArrayList object rather than a copy of the object. Therefore any actions performed on the underlying object will affect the value in the ViewState.

All objects inheriting from System.Object inherit the MemberwiseClone method which makes a "shallow" copy of the object (value types are copied, but reference types just pass their reference). In order to have the ViewState remain unchanged in your scenario, you would need to make a copy of the object and assign it to the ViewState.

.



Relevant Pages

  • Re: Newbie question - Disadvantages of java
    ... >> downwardly assignable to sorts without cast. ... >> Having a type value that is assignable to all object types ... > inherits from all reference types (the only case of multiple ... and is thus assignable to any reference type ...
    (comp.lang.java.programmer)
  • Re: Working with Cache and Viewstate
    ... The ArrayList class inherits from System.Object with means it is a reference ... When you set the value of the ViewState variable, ... I'm playing around with Cache and Viewstate. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is StringBuilder class Value type?
    ... up to my level that I have known the StringBuilder class is reference type. ... Someone telling that StringBuilder class is Value type. ... To determine if a type is a valuetype or a reference type, you can look into the MSDN, lookup the type's documentation page, and you can see if it inherits from a class or it is a class itself -> reference type, if it is a struct or if it inherits from System.ValueType, it is a value type. ... My .NET blog: http://weblogs.asp.net/fbouma ...
    (microsoft.public.dotnet.general)
  • Control wont serialize
    ... I created an assembly with a custom class called myTable that inherits from "System.Web.UI.WebControls.Table" so that I can mark it as serializable. ... I am attempting to put this control in viewstate but on doing so throws the error: ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: Newbie question - Disadvantages of java
    ... "Thomas G. Marshall" ... >> inherits from all reference types (the only case of multiple ... and is thus assignable to any reference type ...
    (comp.lang.java.programmer)