Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C#
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
C# Programming Guide
Unsafe Code and Pointers (C# Programming Guide)

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. For more information about pointers, see the topic Pointer types.

NoteNote:

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. The CLR 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. For more information, see Security (C# Programming Guide).

Unsafe code has the following properties:

  • Methods, types, and code blocks can be defined as unsafe.

  • In some cases, unsafe code may increase an application's performance by removing array bounds checks.

  • Unsafe code is required when you call native functions that require pointers.

  • Using unsafe code introduces security and stability risks.

  • In order for C# to compile unsafe code, the application must be compiled with /unsafe.

For more information, see the following sections in the C# Language Specification:

  • 18 Unsafe Code

  • B 3 Grammar extensions for unsafe code

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker