I want to convert a byte* to a byte[], but I also want to have a reusable function to do this:
byte*
byte[]
public unsafe static T[] Create
5条回答 悲哀的现实 (楼主) 2021-01-03 14:53 As of C# 7.3 this is possible as follows: public unsafe static T[] Create(T* ptr, int length) where T: unmanaged { T[] array = new T[length]; for (int i = 0; i < length; i++) array[i] = ptr[i]; return array; } 0 讨论(0) 查看其它5个回答 发布评论: 提交评论 加载中... 自定义标题段落格式字体字号代码语言点击上传x 验证码 看不清? 提交回复
As of C# 7.3 this is possible as follows:
public unsafe static T[] Create(T* ptr, int length) where T: unmanaged { T[] array = new T[length]; for (int i = 0; i < length; i++) array[i] = ptr[i]; return array; }
热议问题