C#


ROSLYN.PERFORMANCE.CA1846 : Prefer 'AsSpan' over 'Substring' (C#)

See Roslyn-Detected C# Warning Classes for more information.

Summary

'AsSpan' is more efficient then 'Substring'. 'Substring' performs an O(n) string copy, while 'AsSpan' does not and has a constant cost.

This check corresponds to Roslyn rule CA1846. For full rule details, see the Microsoft website: CA1846.

Properties

Class Name Prefer 'AsSpan' over 'Substring' (C#)
Significance reliability
Mnemonic ROSLYN.PERFORMANCE.CA1846
Categories None
Availability Available for C# only.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Prefer 'AsSpan' over 'Substring' (C#)"

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.