Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>String.Copy</code> returns a new <code>String</code> and does not yield the same results as </p> <pre><code>String copy = otherString; </code></pre> <p>Try this:</p> <pre><code>using System; class Program { static void Main() { String test = "test"; String test2 = test; String test3 = String.Copy(test); Console.WriteLine(Object.ReferenceEquals(test, test2)); Console.WriteLine(Object.ReferenceEquals(test, test3)); Console.ReadLine(); } } </code></pre> <p>When you set <code>test2 = test</code> these references point to the same <code>String</code>. The <code>Copy</code> function returns a new <code>String</code> reference that has the same <em>contents</em> but as a different object on the heap.</p> <hr> <p><strong>Edit:</strong> There are a lot of folks that are pretty upset that I did not answer the OP's question. I believe that I did answer the question by correcting an incorrect premise in the question itself. Here is an analogous (if not oversimplified) question and answer that will hopefully illustrate my point:</p> <p><strong>Question:</strong></p> <blockquote> <p>I have observed that my car has two doors, one on each side of the car. I believe it to be true that regardless of which door I use I will end up sitting in the driver's seat. What is the purpose of the other door?</p> </blockquote> <p><strong>Answer:</strong></p> <blockquote> <p>Actually it is not true that if you use either door you will end up in the driver's seat. If you use the driver's side door you will end up in the driver's seat and if you use the passenger's side door you will end up in the passenger's seat.</p> </blockquote> <p>Now in this example you could argue that the answer is not really an answer as the question was "what is the purpose of the passenger's side door?". But since that question was wholly based on a misconception of the how the doors worked does it not follow that the refutation of the premise will shed new light on the purpose of the other door by deduction?</p>
    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.
    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