How to use new .NET 9 string.Join(char, ReadOnlySpan<string?>) with ReadOnlySpan<string>? #109829
-
Hi, what is the expected way to use APIs like string.Join(char, ReadOnlySpan<string?>) when I have The problem I'm having is the following example: void Test(ReadOnlySpan<string> span)
{
var joined = string.Join(';', span);
...
} generates warning
I understand the problem but I'm wondering if there is some simple way to overcome this issue (I don't consider suppressing the warning here as a good solution). If not, I'm afraid the usability of such an API is severely harmed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The warning disappears in Meanwhile, you can use |
Beta Was this translation helpful? Give feedback.
The warning disappears in
<LangVersion>preview</LangVersion>
, the new first-class span feature should allow nullability covariance for spans.Meanwhile, you can use
ReadOnlySpan<string?>.CastUp
to workaround this.