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

前端 未结 9 1734
执笔经年
执笔经年 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 09:39

    It is largely about being verifiable. By stating unsafe, the gloves are off - the system can no longer guarantee that your code won't run amok. In most cases it is highly desirable to stay in the safe zone.

    This gets more noticeable with partial trust (addins etc), but is still valuable in regular code.

提交回复
热议问题