ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Redundant fixed pointer declaration

Last modified: 11 February 2024

Fixed size buffer fields are struct members available in unsafe contexts that represent C style inline arrays. Such fields are primarily used for interoperation with native code.

Before C# 7.3 accessing the elements of a fixed size buffer which can possibly reside in memory movable by GC was allowed only after pinning the buffer with the fixed statement, while fixed size buffers guaranteed to be located in non-movable memory could be indexed directly.

The requirement to introduce auxiliary fixed pointer declaration is unjustified for cases when fixed size buffer is only used to access its elements, because unless address of the buffer is stashed somewhere indexing is always safe.

C# 7.3 removed the unneeded limitation for indexing movable fixed size buffers and made their use more natural:

ReSharper detects places where the use of the fixed statement is not required and provides a quick-fix to remove redundant fixed pointer declaration.