Pinning IEnumerables in C#
<p>I'd like to pin IEnumerable implementations in memory with this generic extension method I'm working on. It seems to work fine with arrays but fails with other sequences (lists and collections). here's the method implementation.</p>

<pre><code>    // &lt;summary&gt;
    ///  Pins an IEnumerable of type T in memory
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;param name="sequence"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static GCHandle Pin&lt;T&gt;(this IEnumerable&lt;T&gt; @sequence)
    {
        return GCHandle.Alloc(@sequence, GCHandleType.Pinned);
    }
</code></pre>

<p>Why does it fail for some types but work for others?Could you explain the concept behind this? Is there a better way to do this than my generic approach? Thank you.</p>
