C#:指向double
问题描述:
我有一个声明,在声明中,我想设置一个高度是一个指向双,但得到的错误mesasage:C#:指向double
" Error 1 Pointers and fixed size buffers may only be used in an unsafe context"
,
有人可以告诉我正确的方式来声明双精度型指针?
下面是我的声明,我将高度设置为双重指针(double* height)
,但会收到错误消息。
private static extern bool GetElevation(double dLat, double dLon, double* height);
答
你extern声明也许应该是:
private static extern bool GetElevation(double dLat, double dLon, ref double height);
希望这有助于!
编辑
这question(和接受的答案)可能会脱落一些关于这个问题光。它谈到了ref
与out
(不知道哪个更适合你的情况)和编组。
答
我想你应该:
- 了解更多关于使用指针,什么不安全块是在C#中,这里是一个很好的resource
- 标记您的“不安全”的功能,见下图:
private static unsafe extern bool GetElevation(double dLat, double dLon, double* height)
一旦完成了这一切,那么你可以用/ unsafe开关编译。