CSharp - Unsafe code

来源:互联网 发布:php人事管理系统 编辑:程序博客网 时间:2024/06/01 20:17

/*

Author: Jiangong SUN

*/


To maintain type safety and security, C# does not support pointer arithmetic, by default. However, by using the unsafe keyword, you can define an unsafe context in which pointers can be used. 

In the common language runtime (CLR), unsafe code is referred to as unverifiable code. Unsafe code in C# is not necessarily dangerous; it is just code whose safety cannot be verified by the CLR. TheCLR will therefore only execute unsafe code if it is in a fully trusted assembly. If you use unsafe code, it is your responsibility to ensure that your code does not introduce security risks or pointer errors.

Unsafe code must be compiled by csharp compiler with keyword "/unsafe"

csc /unsafe class.cs


There are 3 types in CSharp language, which are Value types, Reference types, Pointer types. 

Pointer types can only be used in unsafe mode.




原创粉丝点击