C#中如何获取数组首元素的地址

如题所述

int index = 0;
int[] array = new int[] { 1, 2, 3, 4 };
IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(array, index);
// 引用命名空间 System.Runtime.InteropServices
// 使用方法 Marshal.UnsafeAddrOfPinnedArrayElement获取数组指定索引位置的指针
// array表示需要获取地址的数组,index表示索引的位置,返回的指针值的偏移量
// 如果index输入0,则返回数组首地址指针,若为1,则返回数组第二个元素地址指针
// 一般来说,如果没有特殊要求的话,index值输入0就可以了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-05-28
string[] temArr = {textBox1.Text};
List testList = new List(temArr);
String getResult = testList[0];// 获取List集合第一个元素本回答被网友采纳