Cannot use unsafe construct in safe context

博客主要围绕C#中unsafe代码的使用展开,指出不确定特定情况下是否需要unsafe代码,若需要可在项目属性里启用,也能显式指定/unsafe编译器选项,还提及测试了IntPtr大小为4字节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://stackoverflow.com/questions/25953887/how-to-use-unsafe-code-in-safe-contex

I am not sure if you need unsafe code in that case (see answer of @mybirthname).

But when unsafe code is needed, it can be enabled in Project properties.

  • In the main menu, click Project and then <ProjectName> properties...
  • Click on the Build page.
  • Select Allow unsafe code.

Or one can specify /unsafe compiler option explicitly.

 

无法使用unsafe,需要在项目属性里打开。

测试了一下IntPtr的大小是4字节

https://www.cnblogs.com/darrenji/p/3976029.html

 public void TestChuck()
        {
            unsafe
            {

                Console.WriteLine(sizeof(IntPtr));
            }
        }

 

转载于:https://www.cnblogs.com/chucklu/p/11183633.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值