Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要快速将通用 .net 列表中的数据传递给非托管代码,并且由于列表在内部是一个数组,我想固定它并获取指向数据的指针,但基本固定似乎并不指向数据,而是对象本身。
如何获得对 C# 中声明和填充的 List 的包含数组的数据的本地访问?
使用 ToArray 函数,然后固定生成的数组。下面是快速的 ToArray 的源代码。
public T[] ToArray() { T[] array = new T[_size]; Array.Copy(_items, 0, array, 0, _size); return array; }
从技术意义上讲,您可以使用反射来获取列表的 _items 成员,然后将其固定,但是......