We have the following string-like extension method for ReadOnlySpan<char>:
```C#
public static bool Equals(this ReadOnlySpan
However, due to its name, we are unable to leverage the implicit cast from string to `ReadOnlySpan<char>`. The following code throws a compiler error since it fails to match the correct overload.
```C#
string test = "Hello World!";
ReadOnlySpan<char> span = new char[100];
bool result = span.Equals(test, StringComparison.Ordinal);
// Current workarounds - specify the type explicitly or call AsSpan:
// bool result = span.Equals((ReadOnlySpan<char>)test, StringComparison.Ordinal);
// bool result = span.Equals(test.AsSpan(), StringComparison.Ordinal);
// bool result = MemoryExtensions.Equals(span, test, StringComparison.Ordinal);
Error CS0176 Member 'object.Equals(object, object)' cannot be accessed with an instance reference; qualify it with a type name instead
Should we rename the method to SequenceEqual instead?
We already have a SequenceEqual method (which only takes a single argument), which means, we would end up with a non-generic overload, specific to ReadOnlySpan<char>.
C#
public static bool SequenceEqual<T>(this ReadOnlySpan<T> span, ReadOnlySpan<T> other) where T : System.IEquatable<T> {}
public static bool SequenceEqual<T>(this Span<T> span, ReadOnlySpan<T> other) where T : System.IEquatable<T> {}
// ADD:
public static bool SequenceEqual(this ReadOnlySpan<char> span, ReadOnlySpan<char> other, StringComparison comparisonType) {}
The alternative of adding an Equals overload that takes string as the argument will not work in resolving the overload matching issue.
Other alternatives for names:
cc @KrzysztofCwalina, @terrajobst, @VSadov
I think living with the cast, span.Equals((ReadOnlySpan
reasonable until 'better betterness' overload resolution is fixed in the next minor update of the C# compiler
I agree. I had forgotten about the changes to the overload resolution as part of the next minor update.
I just verified that it will work as expected in the future. Closing.
Most helpful comment
I think living with the cast, span.Equals((ReadOnlySpan)test, StringComparison.Ordinal), is reasonable until 'better betterness' overload resolution is fixed in the next minor update of the C# compiler.