c#也可以直接操作内存指针,如下为示例:
unsafe
{byte[] a = {1,2,3};fixed (byte* p1 = a, p2 = &a[^1]){Debugger.Log(1, "test", $"max index:{p2-p1}");Debugger.Log(1, "test", $"address:{(long)p1:X}");Debugger.Log(1, "test", $"第一个元素的值:{*p1}");}
}
p1为a的地址,p2为结尾地址。
注意,这是unsafe的。
参数网址:
fixed statement - pin a moveable variable - C# reference | Microsoft Learn
从这个网址进去,可以进入到c#的内存指针操作的很多内容