dotnet / dotnet/dotnet-api-docs

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

Open
#12,381 2 comments 0 reactions 0 assignees View on GitHub
area-System.Runtime untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### Type of issue

Misleading wording.

### Description

> Two [ReadOnlyMemory](https://learn.microsoft.com/en-us/dotnet/api/system.readonlymemory-1?view=net-10.0) 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` 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).

[^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

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.