Skip to content

Documentation of ReadOnlyMemory<T>.Equals(ReadOnlyMemory<T>) is technically ambiguous #12381

@mfrischknecht

Description

@mfrischknecht

Type of issue

Misleading wording.

Description

Two ReadOnlyMemory objects are equal if the memory regions point to the same array and have the same length. The method does not check to see if the contents are equal.

The wording here sounds like the ReadOnlyMemory<T> only compares _object and _length 1 internally, ignoring the actual offset of the slice. The implementation seems to do the sensible thing 2 and return true iff both instances point to the same memory region, however (at least on a naive read-through; I'm not sure about the possible edge cases the internal constructor 3 might introduce).

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.readonlymemory-1.equals?view=net-10.0#system-readonlymemory-1-equals(system-readonlymemory((-0)))

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/ReadOnlyMemory`1.xml

Document Version Independent Id

c8fe03ad-b230-bf63-cd15-c862faa1eb22

Platform Id

ef16dd22-d568-3bdd-b282-372e16488fd6

Article author

@dotnet-bot

Footnotes

  1. https://github.com/dotnet/runtime/blob/a962f34b0d502d551534bec84493edee67783771/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs#L26

  2. https://github.com/dotnet/runtime/blob/a962f34b0d502d551534bec84493edee67783771/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs#L383

  3. https://github.com/dotnet/runtime/blob/a962f34b0d502d551534bec84493edee67783771/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs#L93

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions