Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since answer has already been given, let me just explain why your original code didn't work for you:</p> <blockquote> <p>Which, seems strange because you should be able to do the above operations based on the where T : struct constraint on the method.</p> </blockquote> <p>Not really. You can have raw pointers to <em>unmanaged types</em>. This is defined as follows in the C# language spec (18.2):</p> <blockquote> <p>Unlike references (values of reference types), pointers are not tracked by the garbage collector — the garbage collector has no knowledge of pointers and the data to which they point. For this reason a pointer is not permitted to point to a reference or to a struct that contains references, and the referent type of a pointer must be an <em>unmanaged-type</em>. An <em>unmanaged-type</em> is any type that isn’t a reference-type and doesn’t contain reference-type fields at any level of nesting. In other words, an <em>unmanaged-type</em> is one of the following:</p> <ul> <li><code>sbyte</code>, <code>byte</code>, <code>short</code>, <code>ushort</code>, <code>int</code>, <code>uint</code>, <code>long</code>, <code>ulong</code>, <code>char</code>, <code>float</code>, <code>double</code>, <code>decimal</code>, or <code>bool</code>.</li> <li>Any <em>enum-type</em>.</li> <li>Any <em>pointer-type</em>.</li> <li>Any user-defined <em>struct-type</em> that contains fields of <em>unmanaged-types</em> only.</li> </ul> </blockquote> <p>So there are quite a few restrictions, and for a generic method, <code>T:struct</code> may or may not conform to them for any particular instantiation, so construct like <code>T*</code> is illegal. It would be nice to have a special generic type parameter constraint to cover unmanaged types, but as it stands, there isn't one in the CLR.</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