在C#中使用不安全的代码时出错 [英] Getting error while using unsafe code in C#

查看:121
本文介绍了在C#中使用不安全的代码时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,专家
我是在C#中使用不安全代码的新手.我在使用不安全的代码时遇到错误.

错误:无法获取其地址,获取其大小或声明一个指向托管类型的指针.

示例代码:

Experts
i''m new to using unsafe code in C#. i''m Getting error while using unsafe code.

Error : Cannot take the address of, get the size of, or declare a pointer to a managed type.

Sample code :

public override unsafe void setField(StringField field)
        {         
            StringField* sf = &field; // I'm getting error here
        }



在此先感谢..



Thanks in advance..

推荐答案

错误表示它的意思.仅在需要时才使用不安全的代码,例如访问图像的字节.我认为您在此处所做的尝试没有任何价值.
The error means what it says. Only use unsafe code when you need to, like accessing the bytes of an image. I see no value in what you''re trying to do here.


这篇关于在C#中使用不安全的代码时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆