The main reference is C # Language specification Version 3.0.
Introduction
C # is the main development language on the. NET platform, and unlike the classic C + +, the code written by C # is managed code, and the GC manages the memory, eliminating the new/delete annoyance. However, C # provides unsafe code for certain specific requirements, such as the underlying operating system interface, access to memory-mapped devices, or implementation of time-demanding algorithms.
Unsafe context
Unsafe code can only be written in an unsafe context.
You can use the unsafe modifier to modify:
class, struct, interface, or delegate
field, method, property, event, indexer, operator, instance constructor, destructor, or static constructor
unsafe-statement-block
Type of pointer
In an unsafe context, the pointer type is the same as a reference type or a value type. However, pointer types can be used in typeof outside the unsafe context, although it is not safe to do so.
Type t = typeof (int32*); the return is system.int32*.
Pointer types are represented by unmanaged types or void plus *.
pointer-type:
unmanaged-type *
void *
unmanaged-type:
type
The pointer type before * is called the reference type of the pointer type. It indicates the type of variable that the value of the pointer variable points to.
An unmanaged type is not a reference type and contains no members of any nested reference type.
An unmanaged type is one of the following:
sbyte, Byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
· Any enum-type.
· Any pointer-type.
· Any user-defined struct-type that contains fields of unmanaged-types.
Example:
| Example |
Description |
| byte* |
Pointer to byte |
| char* |
Pointer to Char |
| int** |
Pointer to pointer to int |
| Int*[] |
Single-dimensional array of pointers to int |
| void* |
Pointer to unknown type |