Note that there are some explanatory texts on larger screens.

plurals
  1. POViewState - proper way to store data in collections
    primarykey
    data
    text
    <p>Assume I have a collection of objects</p> <pre><code>List&lt;MyClass&gt; collection = new List&lt;MyClass&gt;(); </code></pre> <p>And a dictionary where these objects will be inserted</p> <pre><code>Dictionary&lt;string, List&lt;MyClass&gt;&gt; sections = new Dictionary&lt;string, List&lt;MyClass&gt;&gt;(); // example of insertion sections["A"].Add(collection[2]); </code></pre> <p>List and dictionary are stored in a <code>ViewState</code>. Will it be more memory-friendly to store identifiers of objects in the dictionary and bind them with objects later, when I need them?</p> <pre><code>Dictionary&lt;string, List&lt;int&gt;&gt; sections = new Dictionary&lt;string, List&lt;int&gt;&gt;(); // example of insertion sections["A"].Add(collection[2].ID); </code></pre> <p>As I understand there will be no performance boost because in the first case dictionary will contain references which are 32/64 bits in size. Is it true?</p> <p><strong>EDIT</strong></p> <p><code>MyClass</code> is a class, not a struct. List and Dictionary are declared like this:</p> <pre><code>private List&lt;MyClass&gt; A { get { if (ViewState["a"] == null) { ViewState["a"] = // retrieve data from db } return (List&lt;MyClass&gt;)ViewState["a"]; } set { ViewState["a"] = value; } } private Dictionary&lt;string, List&lt;MyClass&gt;&gt; B { get { if (ViewState["b"] == null) { ViewState["b"] = new Dictionary&lt;string, List&lt;MyClass&gt;&gt;(); } return (Dictionary&lt;string, List&lt;MyClass&gt;&gt;)ViewState["b"]; } set { ViewState["b"] = value; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload