Unsafe Code

Unsafe code is an ominous name. What developer wants to purposely write unsafe code? In .NET, unsafe code really means potentially unsafe code, which is code or memory that exists outside the normal boundaries of the CLR. For this reason, developers should approach the use of unsafe code with caution.

In unsafe code, developers can access raw pointers. You can use pointer operators, such as * and &, with these pointers. Pointers should be avoided because they interrupt the normal operation of the GC. However, using unsafe pointers is sometimes necessary. For example, porting algorithms from C++ that rely heavily on pointers is one situation in which unsafe pointers might be beneficial.

Managed developers must call unmanaged routines ...

Get Programming Microsoft® Visual C#® 2008: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.