Skip to content

Commit dcea68a

Browse files
authored
Add link to best practices article (#48662)
1 parent e044d98 commit dcea68a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/csharp/language-reference/unsafe-code.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Unsafe code has the following properties:
2727
- Using unsafe code introduces security and stability risks.
2828
- The code that contains unsafe blocks must be compiled with the [**AllowUnsafeBlocks**](compiler-options/language.md#allowunsafeblocks) compiler option.
2929

30+
For information about best practices for unsafe code in C#, see [Unsafe code best practices](../../standard/unsafe-code/best-practices.md).
31+
3032
## Pointer types
3133

3234
In an unsafe context, a type can be a pointer type, in addition to a value type, or a reference type. A pointer type declaration takes one of the following forms:
@@ -148,8 +150,8 @@ internal struct Buffer
148150

149151
Fixed-size buffers differ from regular arrays in the following ways:
150152

151-
- May only be used in an `unsafe` context.
152-
- May only be instance fields of structs.
153+
- Can only be used in an `unsafe` context.
154+
- Can only be instance fields of structs.
153155
- They're always vectors, or one-dimensional arrays.
154156
- The declaration should include the length, such as `fixed char id[8]`. You can't use `fixed char id[]`.
155157

@@ -179,7 +181,7 @@ The preceding code illustrates several of the rules on the function accessed as
179181

180182
- Function pointers can only be declared in an `unsafe` context.
181183
- Methods that take a `delegate*` (or return a `delegate*`) can only be called in an `unsafe` context.
182-
- The `&` operator to obtain the address of a function is allowed only on `static` functions. (This rule applies to both member functions and local functions).
184+
- The `&` operator to obtain the address of a function is allowed only on `static` functions. (This rule applies to both member functions and local functions.)
183185

184186
The syntax has parallels with declaring `delegate` types and using pointers. The `*` suffix on `delegate` indicates the declaration is a *function pointer*. The `&` when assigning a method group to a function pointer indicates the operation takes the address of the method.
185187

@@ -192,3 +194,7 @@ You can learn more about function pointers in the [Function pointer](~/_csharpla
192194
## C# language specification
193195

194196
For more information, see the [Unsafe code](~/_csharpstandard/standard/unsafe-code.md) chapter of the [C# language specification](~/_csharpstandard/standard/README.md).
197+
198+
## See also
199+
200+
- [Unsafe code best practices](../../standard/unsafe-code/best-practices.md)

0 commit comments

Comments
 (0)