C#: Benefit of explicitly stating “unsafe” / compiler option

前端 未结 9 1736
执笔经年
执笔经年 2021-01-12 09:13

I understand pointers and the rare need to use them in C# code. My question is: what is the reasoning behind having to explicitly state \"unsafe\" in a block of code. Additi

9条回答
  •  被撕碎了的回忆
    2021-01-12 10:03

    Nurturing good habits & security. Whenever you use an unsafe block in an assembly, a NativeCode permission will be demanded from the stack. This could of course be done implicitly, but couldn't we also just remove the private keyword completely? I think it's good to force developers to specifically require unsafe code before they can use it.

提交回复
热议问题