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

Code inspection: Possibly wrong string comparison: spans are only equal when pointing to the same memory location

Last modified: 06 August 2024

This inspection reports a potential issue with comparing a span to a string using the == operator, which checks for reference equality, not content equality. Such a comparison checks whether the span and the string are pointing to the same memory location, which is not what you usually want.

To compare the contents of the span and the string, you can use the is operator.