Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <blockquote> <p>Will this pass the tags list by reference</p> </blockquote> </blockquote> <p>No. The <em>list object</em> is passed "by value" (but see next). (<code>ref</code> or <code>out</code> is required to <a href="http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference" rel="nofollow">"pass by reference"</a> in C#, but that is not being done here, nor does it need to be.)</p> <blockquote> <blockquote> <p>and modify the original passed list?</p> </blockquote> </blockquote> <p>Yes. This is because the <em>list object</em> is passed. And <em>that list object</em> is mutated. Passing a reference type (anything defined with <code>class</code>) <em>never</em> implicitly makes a copy/clone/duplicate. An object is what it is.</p> <p>Now, back to "pass by value": the "value passed" is the value of the "reference" (internal, no need to concern with this): this calling strategy is better known as <a href="http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing" rel="nofollow">Call/Pass By Object Sharing</a> in a langauge like C#. The <em>same object</em> is <em>shared</em> (just as if it were assigned to two different variables). (Value types -- a <code>struct</code> -- are different in that they (<em>often</em>) are copied/duplicated on the stack, but a <code>List&lt;T&gt;</code> is a <code>class</code>.)</p> <blockquote> <blockquote> <p>Or should I be doing something along the lines of </p> </blockquote> </blockquote> <p>It depends upon the desired semantics. Is the caller <em>expecting</em> the side-effects directly or indirectly? Can the mutation side-effect lead to unexpected scenarios? Make sure to document it either way. (I prefer the way that guarantees the initial object is not mutated.)</p> <p>Hope that clears some things up.</p> <p>Happy coding.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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