Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is perhaps easier to understand if you think about the underlying representation (even though this really is an implementation detail). Here is a collection of strings:</p> <pre><code>IEnumerable&lt;string&gt; strings = new[] { "A", "B", "C" }; </code></pre> <p>You can think of the <code>strings</code> as having the following representation:</p> <pre> [0] : string reference -> "A" [1] : string reference -> "B" [2] : string reference -> "C" </pre> <p>It is a collection of three elements, each being a reference to a string. You can cast this to a collection of objects:</p> <pre><code>IEnumerable&lt;object&gt; objects = (IEnumerable&lt;object&gt;) strings; </code></pre> <p>Basically it is the same representation except now the references are object references:</p> <pre> [0] : object reference -> "A" [1] : object reference -> "B" [2] : object reference -> "C" </pre> <p>The representation is the same. The references are just treated differently; you can no longer access the <code>string.Length</code> property but you can still call <code>object.GetHashCode()</code>. Compare this to a collection of ints:</p> <pre><code>IEnumerable&lt;int&gt; ints = new[] { 1, 2, 3 }; </code></pre> <pre> [0] : int = 1 [1] : int = 2 [2] : int = 3 </pre> <p>To convert this to an <code>IEnumerable&lt;object&gt;</code> the data has to be converted by boxing the ints:</p> <pre> [0] : object reference -> 1 [1] : object reference -> 2 [2] : object reference -> 3 </pre> <p>This conversion requires more than a cast.</p>
 

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