读书人

C#的摘引能不能像C指针一样用于访问一

发布时间: 2011-12-24 23:03:24 作者: rapoo

C#的引用能不能像C指针一样用于访问一个数组
就像下面这段C代码,遍历一个数组里的内容:
void func(double *head, int count)
{
int i = 0;
for(i = 0; i < count; ++i, ++head)
{
*head += 2.0;
}
}

C#里能否也这样:
method(ref double head, int count)
{
//遍历以head为起始地址的大小为count的数组
}

[解决办法]
是可以的呀,你要把你要用指针操作的哪一段代码放到
unsafe
{
}
之中呀,因为,c#这可以真接使用指针呀。

读书人网 >C#

热点推荐