C#: convert generic pointer to array

前端 未结 5 1677
长发绾君心
长发绾君心 2021-01-03 14:29

I want to convert a byte* to a byte[], but I also want to have a reusable function to do this:

public unsafe static T[] Create

        
5条回答
  •  再見小時候
    2021-01-03 15:08

    Seems that the question becomes: How to specify a generic Type to be a simple type.

    unsafe void Foo() : where T : struct
    {
       T* p;
    }
    

    Gives the error:
    Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')

提交回复
热议问题