C# Feature - UTF-8 string literals
Overview
Section titled βOverviewβUTF-8 string literals turn a string literal into UTF-8 bytes directly, which is useful for low-level protocols and performance-sensitive text handling.
Introduced In
Section titled βIntroduced InβC# 11.0 (2022)
byte[] payload = Encoding.UTF8.GetBytes("PING");ReadOnlySpan<byte> payload = "PING"u8;Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- The result is UTF-8 bytes, not a
string. - Use this when APIs already consume bytes or spans.