Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>The address of pr declared in each loop will be stored by the list.</p> </blockquote> <p>No, it won't. The <em>value</em> of the <code>pr</code> variable at the point at which <code>Add</code> is called will be stored in the list. That value is a reference - a reference to the new object you've created.</p> <p>It's important to understand that the value of a variable in C# is <em>never</em> an object. It's always either a value type value, or a reference. Once you get your head round that - and start being very clear about the differences between variables, their values, references, and objects - a lot of things (parameter passing, assignment, garbage collection etc) become much clearer.</p> <p>For example, consider:</p> <pre><code>Button x = new Button(); Button y = x; </code></pre> <p>There's only one <em>object</em> here - the <code>Button</code> created on the first line. There are two <em>variables</em> (<code>x</code> and <code>y</code>) and after the second line they both have the same value (a reference to that object) because of the assignment. They're still independent variables though (assigning a new value to <code>x</code> won't change <code>y</code>). Think about how that is applied to your example - you're calling <code>pl.Add(pr)</code> which just passes the <em>value</em> of <code>pr</code> to the <code>Add</code> method. After that, the <code>pr</code> variable is <em>completely irrelevant</em> as far as the list is concerned. So you could have:</p> <pre><code>pl.Add(pr); pr = null; </code></pre> <p>and the second line wouldn't affect the list at all.</p>
    singulars
    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. 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