|
|
|
|
|
by bzxcvbn
1485 days ago
|
|
The proposal is linked right there in the blog post. You could read it and save some time. https://github.com/dotnet/csharplang/blob/main/proposals/utf... > The language will allow conversions between string constants and byte sequences where the text is converted into the equivalent UTF8 byte representation. Specifically the compiler will allow string_constant_to_UTF8_byte_representation_conversion - implicit conversions from string constants to byte[], Span<byte>, and ReadOnlySpan<byte>. A new bullet point will be added to the implicit conversions §10.2 section. This conversion is not a standard conversion §10.4. byte[] array = "hello"; // new byte[] { 0x68, 0x65, 0x6c, 0x6c, 0x6f }
Span<byte> span = "dog"; // new byte[] { 0x64, 0x6f, 0x67 }
ReadOnlySpan<byte> span = "cat"; // new byte[] { 0x63, 0x61, 0x74 }
> When the input text for the conversion is a malformed UTF16 string then the language will emit an error: const string text = "hello \uD801\uD802";
byte[] bytes = text; // Error: the input string is not valid UTF16
|
|