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)
Before
Section titled “Before”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.